ピボット テーブルのデータの非表示と並べ替え

ピボット テーブルのデータの非表示と並べ替え

Aspose.Cells は、ピボット テーブルでのデータの非表示と並べ替えをサポートします。次のコード スニペットは、スコア列を降順で並べ替え、スコアが 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");

コード スニペットで使用されているソースと出力の Excel ファイルは、参照用に添付されています。

ソースファイル

出力ファイル