用 C++ 过滤从模板文件加载工作簿时的数据类型
Contents
[
Hide
]
有时,您希望在从模板文件构建工作簿时指定要加载的数据类型。过滤加载的数据可以提升性能,特别是在使用 LightCells APIs 时。请使用 LoadOptions.GetLoadFilter() 属性实现此功能。
以下示例代码仅在从模板文件加载工作簿时加载形状对象,您可以从给定链接下载模板文件。下面的屏幕截图显示了模板文件的内容,并且解释了红色和黄色背景中的数据将不会被加载,因为LoadOptions.GetLoadFilter()属性已设置为LoadDataFilterOptions.Shape。
下面的屏幕截图显示了您可以从给定链接下载的输出PDF。在这里,您可以看到红色和黄色背景中的数据不存在,但所有形状都在那里。
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Set the load options, we only want to load shapes and do not want to load data
LoadOptions loadOptions(LoadFormat::Xlsx);
loadOptions.SetLoadFilter(new LoadFilter(LoadDataFilterOptions::All & ~LoadDataFilterOptions::Chart));
// Create workbook object from sample excel file using load options
Workbook workbook(srcDir + u"sampleFilterChars.xlsx", loadOptions);
// Save the output in pdf format
workbook.Save(outDir + u"sampleFilterChars_out.pdf", SaveFormat::Pdf);
std::cout << "File saved successfully." << std::endl;
Aspose::Cells::Cleanup();
}