从模板文件加载工作簿时过滤数据类型
Contents
[
Hide
]
有时,您希望在从模板文件构建工作簿时指定应加载哪种数据类型。过滤加载的数据可以提高您的特定目的的性能,特别是在使用LightCells APIs时。请使用LoadOptions.LoadFilter属性来实现这个目的。
以下示例代码仅在从模板文件加载工作簿时加载形状对象,您可以从给定链接下载模板文件。下面的屏幕截图显示了模板文件的内容,并且解释了红色和黄色背景中的数据将不会被加载,因为LoadOptions.LoadFilter属性已设置为LoadDataFilterOptions.Shape。
下面的屏幕截图显示了您可以从给定链接下载的输出PDF。在这里,您可以看到红色和黄色背景中的数据不存在,但所有形状都在那里。
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 | |
//Source directory | |
string sourceDir = RunExamples.Get_SourceDirectory(); | |
//Output directory | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
// Set the load options, we only want to load shapes and do not want to load data | |
LoadOptions loadOptions = new LoadOptions(LoadFormat.Xlsx); | |
loadOptions.LoadFilter = new LoadFilter(LoadDataFilterOptions.All & ~LoadDataFilterOptions.Chart); | |
// Create workbook object from sample excel file using load options | |
Workbook workbook = new Workbook(sourceDir + "sampleFilterChars.xlsx", loadOptions); | |
// Save the output in pdf format | |
workbook.Save(outputDir + "sampleFilterChars_out.pdf", SaveFormat.Pdf); |