在加载工作簿或工作表时过滤对象
Contents
[
Hide
]
可能的使用场景
在从工作簿中过滤数据时,请使用 LoadOptions.load_filter 属性。如果想要过滤单个工作表中的数据,则需要覆盖 LoadFilter.start_sheet 方法。在创建或使用 LoadFilter 时,请提供适当的 LoadDataFilterOptions 枚举值。
LoadDataFilterOptions 枚举具有以下可能值。
- 所有
- 文档设置
- 单元格空白
- 单元格布尔
- 单元格数据
- 单元格错误
- 单元格数值
- 单元格字符串
- 单元格值
- Chart
- 条件格式
- 数据验证
- 定义名称
- 文档属性
- 公式
- 超链接
- 合并区域
- 数据透视表
- 设置
- 形状
- 表单数据
- 表格设置
- 结构
- 样式
- 表
- VBA
- Xml映射
加载工作簿时过滤对象
以下示例代码说明了如何从工作簿中筛选图表。请查看此代码中使用的示例excel文件和由此生成的输出PDF。从输出PDF中可以看出,所有图表都已从工作簿中筛选出。
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 LoadDataFilterOptions, LoadFilter, LoadOptions, PdfSaveOptions, Workbook | |
from os import os, path | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create directory if it is not already present. | |
IsExists = path.isdir(dataDir) | |
if notIsExists: | |
os.makedirs(dataDir) | |
# Filter charts from the workbook. | |
lOptions = LoadOptions() | |
lOptions.load_filter = LoadFilter(LoadDataFilterOptions.ALL & ~LoadDataFilterOptions.CHART) | |
# Load the workbook with above filter. | |
workbook = Workbook(dataDir + "sampleFilterCharts.xlsx", lOptions) | |
# Save worksheet to a single PDF page. | |
pOptions = PdfSaveOptions() | |
pOptions.one_page_per_sheet = True | |
# Save the workbook in PDF format. | |
workbook.save(dataDir + "sampleFilterCharts.pdf", pOptions) |