用 C++ 过滤从模板文件加载工作簿时的数据类型

Contents
[ ]

以下示例代码仅在从模板文件加载工作簿时加载形状对象,您可以从给定链接下载模板文件。下面的屏幕截图显示了模板文件的内容,并且解释了红色和黄色背景中的数据将不会被加载,因为LoadOptions.GetLoadFilter()属性已设置为LoadDataFilterOptions.Shape

todo:image_alt_text

下面的屏幕截图显示了您可以从给定链接下载的输出PDF。在这里,您可以看到红色和黄色背景中的数据不存在,但所有形状都在那里。

todo:image_alt_text

#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();
}