ピボットテーブルのデータを非表示にしたり並べ替えたり

ピボットテーブルのデータを非表示にしたり並べ替えたり

Aspose.Cells for Node.js via C++は、ピボットテーブル内のデータを非表示や並べ替えすることをサポートしています。以下のコードスニペットは、Score列を降順に並べ替え、60未満のスコアの行を非表示にする例です。

const AsposeCells = require("aspose.cells.node");
//directories
var sourceDir = RunExamples.Get_SourceDirectory();
var outputDir = RunExamples.Get_OutputDirectory();
var workbook = new AsposeCells.Workbook(sourceDir + "PivotTableHideAndSortSample.xlsx");
var worksheet = workbook.getWorksheets().get(0);
var pivotTable = worksheet.getPivotTables().get(0);
var dataBodyRange = pivotTable.getDataBodyRange();
var currentRow = 3;
var rowsUsed = dataBodyRange.endRow;
//Sorting score in descending
var field = pivotTable.getRowFields().get(0);
field.setIsAutoSort(true);
field.setIsAscendSort(false);
field.setAutoSortField(0);
pivotTable.refreshData();
pivotTable.calculateData();
//Hiding rows with score less than 60
while (currentRow < rowsUsed)
{
var cell = worksheet.getCells().get(currentRow, 1);
var score = cell.getFloatValue();
if (score < 60)
{
worksheet.getCells().hideRow(currentRow);
}
currentRow = currentRow + 1;
}
pivotTable.refreshData();
pivotTable.calculateData();
//Saving the Excel file
workbook.save(outputDir + "PivotTableHideAndSort_out.xlsx");

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

ソースファイル

出力ファイル