Working with data display formats of DataField in Pivot Table

“Rank Smallest to Largest” and “Rank Largest to Smallest” display format option

ASpose.Cells provides the ability to set the display format option for pivot fields. For this, the API provides the PivotShowValuesSetting.setCalculationType property. To rank largest to smallest, you may set the PivotShowValuesSetting.setCalculationType property to PivotFieldDataDisplayFormat.RankLargestToSmallest. The following code snippet demonstrates setting the display format options.

Sample source and output files can be downloaded from here for testing the sample code:

Source Excel File

Output Excel File

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