ピボットテーブルでのデータフィールドの表示形式を操作する
Contents
[
Hide
]
Aspose.Cellsは、データフィールドのすべての表示形式をサポートしています。
「最小から最大への順位付け」と「最大から最小への順位付け」表示形式オプション
Aspose.Cells は、ピボットフィールドの表示形式オプションを設定する機能を提供しています。このために、API は PivotField.DataDisplayFormat プロパティを提供します。最大から最小へのランクを行うには、PivotField.DataDisplayFormat プロパティを PivotFieldDataDisplayFormat.RANK_LARGEST_TO_SMALLEST に設定できます。次のコードスニペットは、表示形式オプションを設定する方法を示しています。
サンプルソースと出力ファイルは、テスト用のサンプルコードをダウンロードできます:
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-Java | |
// directories | |
String sourceDir = Utils.Get_SourceDirectory(); | |
String outputDir = Utils.Get_OutputDirectory(); | |
// Load a template file | |
Workbook workbook = new Workbook(sourceDir + "PivotTableSample.xlsx"); | |
// Get the first worksheet | |
Worksheet sheet = workbook.getWorksheets().get(0); | |
int pivotIndex = 0; | |
// Get the pivot tables in the sheet | |
PivotTable pivotTable = sheet.getPivotTables().get(pivotIndex); | |
// Accessing the data fields. | |
PivotFieldCollection pivotFields = pivotTable.getDataFields(); | |
// Accessing the first data field in the data fields. | |
PivotField pivotField = pivotFields.get(0); | |
// Setting data display format | |
pivotField.setDataDisplayFormat(PivotFieldDataDisplayFormat.RANK_LARGEST_TO_SMALLEST); | |
pivotTable.calculateData(); | |
// Saving the Excel file | |
workbook.save(outputDir + "PivotTableDataDisplayFormatRanking_out.xlsx"); |