ピボットテーブルでのデータフィールドの表示形式を操作する
Contents
[
Hide
]
Aspose.Cells for Node.js via C++は、DataFieldのすべてのデータ表示形式をサポートしています。
「最小から最大への順位付け」と「最大から最小への順位付け」表示形式オプション
ASpose.Cellsは、ピボットフィールドの表示形式オプションを設定する機能を提供しています。このためのAPIはPivotShowValuesSetting.setCalculationTypeプロパティを提供しています。最大から最小への順位付けを行うには、PivotShowValuesSetting.setCalculationTypeプロパティをPivotFieldDataDisplayFormat.RankLargestToSmallestに設定できます。次のコードスニペットは、表示形式オプションの設定方法を示しています。
サンプルソースと出力ファイルは、テスト用のサンプルコードをダウンロードできます:
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"); |