Arbeiten mit Datenanzeigeformaten von DataField im Pivot Table

Wie man die Display-Formatoption “Von klein nach groß” und “Von groß nach klein” einstellt

Aspose.Cells für Python via .NET bietet die Möglichkeit, die Anzeigeformatoption für Pivot-Felder festzulegen. Hierfür bietet die API die PivotField.data_display_format-Eigenschaft. Um von groß nach klein zu rangieren, können Sie die PivotField.data_display_format-Eigenschaft auf PivotFieldDataDisplayFormat.RANK_LARGEST_TO_SMALLEST setzen. Der folgende Code zeigt das Festlegen der Anzeigeformatoptionen.

Die Beispielsquell- und Ausgabedateien können hier für das Testen des Beispielcodes heruntergeladen werden:

Quell-Excel-Datei

Ausgabe-Excel-Datei

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