[]
GcExcel Java允许用户能够将过滤器应用于切片器,从而使用户能够快速有效地分析电子表格中的批量信息。
参考以下代码在切片器中执行过滤操作
// Adding data to the table
worksheet.getRange("A:F").setColumnWidth(15);
worksheet.getRange("A1:F16").setValue(sourceData);
ITable table = worksheet.getTables().add(worksheet.getRange("A1:F16"), true);
table.getColumns().get(3).getDataBodyRange().setNumberFormat("$#,##0.00");
// Create slicer cache for the table.
ISlicerCache cache = workbook.getSlicerCaches().add(table, "Category", "categoryCache");
// Add slicer for table
ISlicer slicer1 = cache.getSlicers().add(workbook.getWorksheets().get("Sheet1"), "cate1",
"Category", 30, 550, 100, 200);
// Execute the do filter operation. Here we are filtering vegetables.
slicer1.getSlicerCache().getSlicerItems().get("Vegetables").setSelected(false);
为了清除切片器过滤器,请参考以下示例代码。
// Adding data to the table
worksheet.getRange("A:F").setColumnWidth(15);
worksheet.getRange("A1:F16").setValue(sourceData);
ITable table = worksheet.getTables().add(worksheet.getRange("A1:F16"), true);
table.getColumns().get(3).getDataBodyRange().setNumberFormat("$#,##0.00");
// Create slicer cache for table.
ISlicerCache cache = workbook.getSlicerCaches().add(table, "Category", "categoryCache");
// Add slicer for table
ISlicer slicer1 = cache.getSlicers().add(workbook.getWorksheets().get("Sheet1"), "cate1",
"Category", 30, 550, 100, 200);
// Execute the do filter operation. Here we are filtering vegetables.
slicer1.getSlicerCache().getSlicerItems().get("Vegetables").setSelected(false);
// Clear the slicer filter.
slicer1.getSlicerCache().clearAllFilters();