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é PivotField.DataDisplayFormat. Pour classer du plus grand au plus petit, vous pouvez définir la propriété PivotField.DataDisplayFormat sur PivotFieldDataDisplayFormat.RANK_LARGEST_TO_SMALLEST. Le code suivant dé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:
// 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"); |