更新切片器
Contents
[
Hide
]
可能的使用场景
如果您想在Microsoft Excel中更新数据透视表,选择或取消选择其项,它将相应地更新数据透视表或旋转表。请使用Slicer.slicer_cache.slicer_cache_items通过Aspose.Cells为Python via .NET选择或取消选择切片项,然后调用Slicer.refresh()方法来更新切片表或数据透视表。
如何使用 Aspose.Cells for Python Excel 库更新数据透视表筛选器
以下示例代码加载包含现有数据透视切片器的示例 Excel 文件,取消选择数据透视切片器的第 2 和第 3 个项目,并刷新数据透视切片器,然后将工作簿保存为输出 Excel 文件。以下屏幕截图显示了示例代码对示例 Excel 文件的效果。如屏幕截图所示,使用选定项目刷新数据透视切片器也已相应地刷新了数据透视表。
示例代码
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
from aspose.cells import Workbook | |
# Load sample Excel file containing slicer. | |
wb = Workbook("sampleUpdatingSlicer.xlsx") | |
# Access first worksheet. | |
ws = wb.worksheets[0] | |
# Access the first slicer inside the slicer collection. | |
slicer = ws.slicers[0] | |
# Access the slicer items. | |
scItems = slicer.slicer_cache.slicer_cache_items | |
items = slicer.slicer_cache.slicer_cache_items | |
for item in items: | |
if item.value == "Pink" or item.value == "Green": | |
item.selected = False | |
slicer.refresh() | |
wb.save("out.xlsx") |