更新切片器
Contents
[
Hide
]
可能的使用场景
如果要在 Microsoft Excel 中更新切片器,选择或取消选择其项目,它将相应地更新切片器表或数据透视表。请用切片器.SlicerCache.SlicerCacheItems使用 Aspose.Cells 选择或取消选择切片器项目,然后调用切片器.refresh() 方法来更新切片器表或数据透视表。
更新切片器
下面的示例代码加载示例 Excel 文件包含一个现有的切片器。它取消选择切片器的第 2 项和第 3 项并刷新切片器。然后将工作簿另存为输出Excel文件.以下屏幕截图显示了示例代码对示例 Excel 文件的影响。正如您在屏幕截图中所见,使用所选项目刷新切片器也相应地刷新了数据透视表。
示例代码
This file contains 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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// Load sample Excel file containing slicer. | |
Workbook wb = new Workbook(srcDir + "sampleUpdatingSlicer.xlsx"); | |
// Access first worksheet. | |
Worksheet ws = wb.getWorksheets().get(0); | |
// Access the first slicer inside the slicer collection. | |
Slicer slicer = ws.getSlicers().get(0); | |
// Access the slicer items. | |
SlicerCacheItemCollection scItems = slicer.getSlicerCache().getSlicerCacheItems(); | |
// Unselect 2nd and 3rd slicer items. | |
scItems.get(1).setSelected(false); | |
scItems.get(2).setSelected(false); | |
// Refresh the slicer. | |
slicer.refresh(); | |
// Save the workbook in output XLSX format. | |
wb.save(outDir + "outputUpdatingSlicer.xlsx", SaveFormat.XLSX); |