Arbeiten mit Datenanzeigeformaten von DataField im Pivot Table

“Rang Kleinste bis Größte” und “Rang Größte bis Kleinste” Anzeigeformat-Option

Aspose.Cells bietet die Möglichkeit, die Anzeigeformatoptionen für Pivot-Felder festzulegen. Für dies bietet die API die Eigenschaft PivotField.DataDisplayFormat. Um von größtem zu kleinestem Rang zu sortieren, können Sie die PivotField.DataDisplayFormat Eigenschaft auf PivotFieldDataDisplayFormat.RANK_LARGEST_TO_SMALLEST setzen. Der folgende Codeausschnitt zeigt das Festlegen der Anzeigeformatoptionen.

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

Quelldatei Excel

Ausgabedatei Excel

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