ピボットテーブルでのデータフィールドの表示形式を操作する
Contents
[
Hide
]
Aspose.Cellsは、データフィールドのすべての表示形式をサポートしています。
「最小から最大への順位付け」と「最大から最小への順位付け」表示形式オプション
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"); |