清除数据透视表中的筛选器

可能的使用场景

当你创建了已知数据的数据透视表并想筛选数据时,你需要学习并使用筛选器。它可以帮助你有效筛选出所需数据。使用Aspose.Cells for Node.js via C++ API,你可以对数据透视表中的字段值进行筛选。

如何在Excel中清除数据透视表中的筛选器

在 Excel 中清除数据透视表中的筛选,按照以下步骤操作:

  1. 选择要清除筛选的数据透视表。
  2. 单击数据透视表中要清除筛选的下拉箭头。
  3. 从下拉菜单中选择“清除筛选”。
  4. 如果您要清除数据透视表中的所有筛选,还可以在 Excel 的“数据透视表分析”选项卡上单击“清除筛选”按钮。

如何使用Aspose.Cells for Node.js via C++清除数据透视表中的筛选器。

使用Aspose.Cells for Node.js via C++清除数据透视表中的筛选器。请参见下面的示例代码。

  1. 设置数据并创建基于该数据的数据透视表。
  2. 在数据透视表的行字段上添加筛选。
  3. output XLSX 格式保存工作簿。执行示例代码后,将在工作表中添加带有 top10 筛选的数据透视表。
  4. 清除特定数据透视字段上的筛选。执行清除筛选的代码后,将清除特定数据透视字段上的筛选。请检查 output XLSX

示例代码

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");