ピボットテーブルのフィルタをクリアする
Contents
[
Hide
]
可能な使用シナリオ
既知のデータでピボットテーブルを作成し、フィルタリングしたい場合、フィルタを学び、使用する必要があります。これにより、必要なデータを効果的に抽出できます。Aspose.Cells for Node.js via C++ APIを使用して、ピボットテーブルのフィールド値に対して操作できます。
Excelのピボットテーブルでフィルターをクリアする方法
Excelでピボットテーブルのフィルタをクリアするには、以下の手順に従います:
- クリアしたいPivotTableを選択します。
- ピボットテーブルでクリアしたいフィルタのドロップダウン矢印をクリックします。
- ドロップダウンメニューから「フィルタをクリア」を選択します。
- ピボットテーブルからすべてのフィルタをクリアしたい場合は、ExcelのリボンのPivotTable Analyzeタブで「フィルタをクリア」ボタンをクリックすることもできます。
Aspose.Cells for Node.js via C++を使用してピボットテーブルのフィルタをクリアする方法。
Aspose.Cells for Node.js via C++を使用してピボットテーブルのフィルタをクリアしてください。以下のサンプルコードを参照してください。
- データを設定し、それに基づいてPivotTableを作成します。
- ピボットテーブルの行フィールドにフィルタを追加します。
- output XLSX形式でブックを保存します。サンプルコードを実行した後は、ワークシートにトップ10フィルタが追加されたピボットテーブルが表示されます。
- 特定のピボットフィールドのフィルタをクリアします。フィルタをクリアするコードを実行した後、特定のピボットフィールドのフィルタがクリアされます。output XLSXをご確認ください。
サンプルコード
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const AsposeCells = require("aspose.cells.node"); | |
//Instantiating an Workbook object | |
var workbook = new AsposeCells.Workbook(); | |
//Obtaining the reference of the newly added worksheet | |
var ws = workbook.getWorksheets().get(0); | |
var cells = ws.getCells(); | |
//Setting the value to the cells | |
var cell = cells.get("A1");; | |
cell.putValue("Fruit"); | |
cell = cells.get("B1"); | |
cell.putValue("Count"); | |
cell = cells.get("A2"); | |
cell.putValue("Apple"); | |
cell = cells.get("A3"); | |
cell.putValue("Mango"); | |
cell = cells.get("A4"); | |
cell.putValue("Blackberry"); | |
cell = cells.get("A5"); | |
cell.putValue("Cherry"); | |
cell = cells.get("A6"); | |
cell.putValue("Guava"); | |
cell = cells.get("A7"); | |
cell.putValue("Carambola"); | |
cell = cells.get("A8"); | |
cell.putValue("Banana"); | |
cell = cells.get("B2"); | |
cell.putValue(5) | |
cell = cells.get("B3"); | |
cell.putValue(3) | |
cell = cells.get("B4"); | |
cell.putValue(6) | |
cell = cells.get("B5"); | |
cell.putValue(4) | |
cell = cells.get("B6"); | |
cell.putValue(5) | |
cell = cells.get("B7"); | |
cell.putValue(2) | |
cell = cells.get("B8"); | |
cell.putValue(20) | |
//Adding a PivotTable to the worksheet | |
var i = ws.getPivotTables().add("=A1:B8", "D10", "PivotTable1"); | |
//Accessing the instance of the newly added PivotTable | |
var pivotTable = ws.getPivotTables().get(i); | |
pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Row, 0); | |
pivotTable.addFieldToArea(AsposeCells.PivotFieldType.Data, "Count"); | |
pivotTable.getDataFields().get(0).setFunction(AsposeCells.ConsolidationFunction.Sum); | |
var field = pivotTable.getRowFields().get(0); | |
field.setIsAutoSort(true); | |
field.setIsAscendSort(false); | |
field.setAutoSortField(0); | |
//Add top10 filter | |
var index = pivotTable.getPivotFilters().add(field.getBaseIndex(), AsposeCells.PivotFilterType.Count); | |
var filter = pivotTable.getPivotFilters().get(index); | |
filter.getAutoFilter().filterTop10(0, True, False, 5); | |
pivotTable.refreshData(); | |
pivotTable.calculateData(); | |
workbook.save("out_add.xlsx"); | |
//Clear PivotFilter from the specific PivotField | |
pivotTable.getPivotFilters().clearFilter(field.getBaseIndex()); | |
pivotTable.refreshData(); | |
pivotTable.calculateData(); | |
workbook.save("out_delete.xlsx"); |