在加载Excel工作簿时过滤VBA项目
Contents
[
Hide
]
在C#中加载Excel工作簿时过滤VBA项目
一些 .xlsm/.xslb 文件包含极其大量的宏(或者非常非常长的宏)。Aspose.Cells 在打开这样的工作簿时将无条件加载这些(元)数据。但是在需要提取大量工作簿的工作表名称时可能需要控制此行为 LoadDataFilterOptions,从而跳过这些不需要的内容。为此,引入了一个新选项,LoadDataFilterOptions.VBA。
示例代码
以下示例代码加载工作簿,仅过滤 VBA。可以从以下链接下载用于测试此功能的示例文件:
sampleMacroEnabledWorkbook.xlsm
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-.NET | |
// Set the load options, we do not want to load VBA | |
LoadOptions loadOptions = new LoadOptions(LoadFormat.Auto); | |
loadOptions.LoadFilter = new LoadFilter(LoadDataFilterOptions.All & ~LoadDataFilterOptions.VBA); | |
// Create workbook object from sample excel file using load options | |
Workbook book = new Workbook(sourceDir + "sampleMacroEnabledWorkbook.xlsm", loadOptions); | |
// Save the output in pdf format | |
book.Save(outputDir + "OutputSampleMacroEnabledWorkbook.xlsm", SaveFormat.Xlsm); |