Utilisation des formats d'affichage de 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 offre la possibilité de définir l’option de format d’affichage pour les champs pivots. Pour cela, le API fournit lePivotField.DataDisplayFormatPivotField.DataDisplayFormat la propriété. Pour classer le plus grand au plus petit, vous pouvez définir lePivotField.DataDisplayFormatPivotField.DataDisplayFormatpropriété àPivotFieldDataDisplayFormat.RankLargestToSmallest. L’extrait de code suivant illustre la définition des options de format d’affichage.

Des exemples de fichiers source et de sortie peuvent être téléchargés ici pour tester l’exemple de code :

Fichier Excel source

Fichier Excel de sortie

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// directories
string sourceDir = RunExamples.Get_SourceDirectory();
string outputDir = RunExamples.Get_OutputDirectory();
// Load a template file
Workbook workbook = new Workbook(sourceDir + "PivotTableSample.xlsx");
// Get the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
int pivotIndex = 0;
// Accessing the PivotTable
PivotTable pivotTable = worksheet.PivotTables[pivotIndex];
// Accessing the data fields.
PivotFieldCollection pivotFields = pivotTable.DataFields;
// Accessing the first data field in the data fields.
PivotField pivotField = pivotFields[0];
// Setting data display format
pivotField.ShowValuesSetting.CalculationType = PivotFieldDataDisplayFormat.RankLargestToSmallest;
pivotTable.CalculateData();
// Saving the Excel file
workbook.Save(outputDir + "PivotTableDataDisplayFormatRanking_out.xlsx");