通过 Microsoft Excel 与 C++ 自动刷新 OLE 对象

Contents
[ ]

以下示例代码加载了带有非真实OLE图像的示例Excel文件。OLE对象实际上是Microsoft Word文档,但示例Excel文件显示的动物图像而非Microsoft Word图像。不过,如果你打开输出Excel文件,会看到Microsoft Excel显示了正确的OLE图像。

#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;

int main()
{
    Aspose::Cells::Startup();

    // Source directory path
    U16String srcDir(u"..\\Data\\01_SourceDirectory\\");

    // Create workbook object from your sample excel file
    Workbook wb(srcDir + u"sample.xlsx");

    // Access first worksheet
    Worksheet sheet = wb.GetWorksheets().Get(0);

    // Set auto load property of first ole object to true
    sheet.GetOleObjects().Get(0).SetAutoLoad(true);

    // Save the workbook in xlsx format
    wb.Save(srcDir + u"RefreshOLEObjects_out.xlsx", SaveFormat::Xlsx);

    std::cout << "OLE object refreshed successfully!" << std::endl;

    Aspose::Cells::Cleanup();
}