Travail sur les formats d affichage des données de DataField dans le tableau croisé dynamique

Option de format d’affichage “Classer du plus petit au plus grand” et “Classer du plus grand au plus petit”

ASpose.Cells permet de définir l’option de format d’affichage pour les champs de tableau croisé dynamique. Pour cela, l’API fournit la propriété PivotShowValuesSetting.setCalculationType. Pour classer du plus grand au plus petit, vous pouvez définir la propriété PivotShowValuesSetting.setCalculationType sur PivotFieldDataDisplayFormat.RankLargestToSmallest. Le code suivant montre comment définir les options de format d’affichage.

Les fichiers source et de sortie de l’échantillon peuvent être téléchargés d’ici pour tester le code d’échantillon:

Fichier Excel source

Fichier Excel de sortie

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