在数据透视表中处理数据字段的数据显示格式
Contents
[
Hide
]
Aspose.Cells for Node.js via C++支持所有数据字段的数据显示格式。
“从最小到最大的排名”和“从最大到最小的排名”显示格式选项
ASpose.Cells提供了设置数据透视字段显示格式选项的功能。为此,API提供了PivotShowValuesSetting.setCalculationType属性。为了从最大到最小排名,您可以将PivotShowValuesSetting.setCalculationType属性设置为PivotFieldDataDisplayFormat.RankLargestToSmallest。以下代码片段演示了设置显示格式选项。
可从此处下载示例源文件和输出文件以测试示例代码:
[源 Excel 文件](101089332.xlsx)
[输出 Excel 文件](101089333.xlsx)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const AsposeCells = require("aspose.cells.node"); | |
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// directories | |
var sourceDir = RunExamples.Get_SourceDirectory() | |
var outputDir = RunExamples.Get_OutputDirectory() | |
// Load a template file | |
var workbook = new AsposeCells.Workbook(sourceDir + "PivotTableSample.xlsx"); | |
// Get the first worksheet | |
var worksheet = workbook.getWorksheets().get(0); | |
var pivotIndex = 0; | |
// Accessing the PivotTable | |
var pivotTable = worksheet.getPivotTables().get(pivotIndex); | |
// Accessing the data fields. | |
var pivotFields = pivotTable.getDataFields(); | |
// Accessing the first data field in the data fields. | |
var pivotField = pivotFields.get(0); | |
// Setting data display format | |
pivotField.getShowValuesSetting().setCalculationType(AsposeCells.PivotFieldDataDisplayFormat.RankLargestToSmallest); | |
pivotTable.calculateData(); | |
// Saving the Excel file | |
workbook.save(outputDir + "PivotTableDataDisplayFormatRanking_out.xlsx"); |