在数据透视表中处理数据字段的数据显示格式

“从最小到最大的排名”和“从最大到最小的排名”显示格式选项

ASpose.Cells提供了设置数据透视字段显示格式选项的功能。为此,API提供了PivotField.DataDisplayFormat属性。为了从最大到最小排名,您可以将PivotField.DataDisplayFormat属性设置为PivotFieldDataDisplayFormat.RankLargestToSmallest。以下代码片段演示了设置显示格式选项。

可从此处下载示例源文件和输出文件以测试示例代码:

【源 Excel 文件】(101089332.xlsx)

【输出 Excel 文件】(101089333.xlsx)

// 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");