使用数据透视表中DataField的数据显示格式
Contents
[
Hide
]
Aspose.Cells 支持DataField的所有数据显示格式。
“从最小到最大排列”和“从最大到最小排列”显示格式选项
ASpose.Cells 提供了为数据透视字段设置显示格式选项的能力。为此,API 提供了PivotField.DataDisplayFormat财产。要从大到小排列,您可以设置PivotField.DataDisplayFormat财产给PivotFieldDataDisplayFormat.RankLargestToSmallest.以下代码片段演示了设置显示格式选项。
可以从此处下载示例源文件和输出文件以测试示例代码:
This file contains 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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// directories | |
string sourceDir = RunExamples.Get_SourceDirectory(); | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
// Load a template file | |
Workbook workbook = new Workbook(sourceDir + "PivotTableSample.xlsx"); | |
// Get the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
int pivotIndex = 0; | |
// Accessing the PivotTable | |
PivotTable pivotTable = worksheet.PivotTables[pivotIndex]; | |
// Accessing the data fields. | |
PivotFieldCollection pivotFields = pivotTable.DataFields; | |
// Accessing the first data field in the data fields. | |
PivotField pivotField = pivotFields[0]; | |
// Setting data display format | |
pivotField.ShowValuesSetting.CalculationType = PivotFieldDataDisplayFormat.RankLargestToSmallest; | |
pivotTable.CalculateData(); | |
// Saving the Excel file | |
workbook.Save(outputDir + "PivotTableDataDisplayFormatRanking_out.xlsx"); |