Working with data display formats of DataField in Pivot Table

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

Aspose.Cells for Python via .NET provides the ability to set the display format option for pivot fields. For this, the API provides the PivotField.data_display_format property. To rank largest to smallest, you may set the PivotField.data_display_format property to PivotFieldDataDisplayFormat.RANK_LARGEST_TO_SMALLEST. 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

from aspose.cells import Workbook
from aspose.cells.pivot import PivotFieldDataDisplayFormat
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# directories
sourceDir = RunExamples.Get_SourceDirectory()
outputDir = RunExamples.Get_OutputDirectory()
# Load a template file
workbook = Workbook(sourceDir + "PivotTableSample.xlsx")
# Get the first worksheet
worksheet = workbook.worksheets[0]
pivotIndex = 0
# Accessing the PivotTable
pivotTable = worksheet.pivot_tables[pivotIndex]
# Accessing the data fields.
pivotFields = pivotTable.data_fields
# Accessing the first data field in the data fields.
pivotField = pivotFields[0]
# Setting data display format
pivotField.data_display_format = PivotFieldDataDisplayFormat.RANK_LARGEST_TO_SMALLEST
pivotTable.calculate_data()
# Saving the Excel file
workbook.save(outputDir + "PivotTableDataDisplayFormatRanking_out.xlsx")