Masquer et trier les données du tableau croisé dynamique
Masquer et trier les données du tableau croisé dynamique
Aspose.Cells prend en charge la masquage et le tri des données dans le tableau croisé dynamique. Le code suivant démontre cette fonctionnalité en triant la colonne Score dans l’ordre décroissant, puis masque les lignes ayant un score inférieur à 60.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the output directory. | |
String sourceDir = Utils.Get_SourceDirectory(); | |
String outputDir = Utils.Get_OutputDirectory(); | |
Workbook workbook = new Workbook(sourceDir + "PivotTableHideAndSortSample.xlsx"); | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
PivotTable pivotTable = worksheet.getPivotTables().get(0); | |
CellArea dataBodyRange = pivotTable.getDataBodyRange(); | |
int currentRow = 3; | |
int rowsUsed = dataBodyRange.EndRow; | |
// Sorting score in descending | |
PivotField field = pivotTable.getRowFields().get(0); | |
field.setAutoSort(true); | |
field.setAscendSort(false); | |
field.setAutoSortField(0); | |
pivotTable.refreshData(); | |
pivotTable.calculateData(); | |
// Hiding rows with score less than 60 | |
while (currentRow < rowsUsed) | |
{ | |
Cell cell = worksheet.getCells().get(currentRow, 1); | |
double score = (double) cell.getValue(); | |
if (score < 60) | |
{ | |
worksheet.getCells().hideRow(currentRow); | |
} | |
currentRow++; | |
} | |
pivotTable.refreshData(); | |
pivotTable.calculateData(); | |
// Saving the Excel file | |
workbook.save(outputDir + "PivotTableHideAndSort_out.xlsx"); |
Les fichiers Excel source et de sortie utilisés dans l’extrait de code sont joints à titre de référence.