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 Anzeigeformatoption für Pivot-Felder festzulegen. Hierfür stellt die API die Eigenschaft PivotShowValuesSetting.setCalculationType bereit. Um von größtem nach kleinstem Rang zu ordnen, können Sie die PivotShowValuesSetting.setCalculationType Eigenschaft auf PivotFieldDataDisplayFormat.RankLargestToSmallest setzen. Der folgende Codeausschnitt 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

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