在加载Excel工作簿时过滤VBA项目
Contents
[
Hide
]
在Python中加载Excel工作簿时过滤VBA项目
一些.xlam/.xlsb文件具有极大量的宏(或非常长的宏)。Aspose.Cells for Python via .NET在打开此类工作簿时将无条件加载这些(元)数据。您可能需要通过LoadDataFilterOptions控制此行为,当您实际上只需提取大量工作簿的工作表名称,从而跳过此类不需要的内容。这通过引入一个新选项LoadDataFilterOptions.VBA提供了过滤功能。
示例代码
以下示例代码加载工作簿,仅过滤 VBA。可以从以下链接下载用于测试此功能的示例文件:
sampleMacroEnabledWorkbook.xlsm
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, LoadFormat, LoadOptions, SaveFormat, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Set the load options, we do not want to load VBA | |
loadOptions = LoadOptions(LoadFormat.AUTO) | |
loadOptions.load_filter = LoadFilter(LoadDataFilterOptions.ALL & ~LoadDataFilterOptions.VBA) | |
# Create workbook object from sample excel file using load options | |
book = Workbook(sourceDir + "sampleMacroEnabledWorkbook.xlsm", loadOptions) | |
# Save the output in pdf format | |
book.save(outputDir + "OutputSampleMacroEnabledWorkbook.xlsm", SaveFormat.XLSM) |