从模板文件加载工作簿时过滤数据类型
Contents
[
Hide
]
有时,您希望在从模板文件构建工作簿时指定应加载的数据类型。过滤加载的数据可以提高您的特定目的的性能,尤其在使用 LightCells APIs 时。请使用 LoadOptions.getLoadFilter().setLoadDataFilterOptions 属性来实现此目的。
从模板文件加载工作簿时过滤数据类型
以下示例代码仅在从给定链接下载的template file中加载形状对象时加载工作簿。
以下屏幕截图显示了模板文件的内容,并说明了因为已设置LoadOptions.getLoadFilter().setLoadDataFilterOptions 属性为 LoadDataFilterOptions.SHAPE,所以红色和黄色背景的数据将不会加载。
以下屏幕截图显示了从给定链接下载的output 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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(FilterDataWhileLoadingWorkbook.class) + "TechnicalArticles/"; | |
// Set the load options, we only want to load shapes and do not want to load data | |
LoadOptions opts = new LoadOptions(LoadFormat.XLSX); | |
opts.getLoadFilter().setLoadDataFilterOptions(LoadDataFilterOptions.SHAPE); | |
// Create workbook object from sample excel file using load options | |
Workbook wb = new Workbook(dataDir + "sampleFilterDataWhileLoadingWorkbook.xlsx", opts); | |
// Save the output in PDF format | |
wb.save(dataDir + "sampleFilterDataWhileLoadingWorkbook_out.pdf", SaveFormat.PDF); |