加载doc文件失败

将一个用wps软件可以正常打开的doc文件上传后报错 Error 500
https://products.aspose.com/words/cpp/conversion/
C++版本的aspose.words加载也会报错

auto Bytes = ConvertStringToByteArray(doc_data);
auto byteStream = System::MakeObject<System::IO::MemoryStream>(Bytes);
auto load_options = System::MakeObject<Loading::LoadOptions>(System::String(config.word_pwd));
auto doc = System::MakeObject<Document>(byteStream, load_options);

auto dstStream = System::MakeObject<System::IO::MemoryStream>();
doc->Save(dstStream, SaveFormat::Docx);

18a1d33ee5f05328393ade0d01bf7c58.zip (16.8 KB)

@ztthu 问题发生在保存文档时,而不是加载文档时。您的文档包含宏,因此无法保存为 DOCX 格式,因为这是一种无宏格式。因此,您应该在保存之前从文档中删除宏:

System::SharedPtr<Document> doc = System::MakeObject<Document>(u"C:\\Temp\\in.doc");
doc->RemoveMacros();
doc->Save(u"C:\\Temp\\out.docx");

或者将文档保存为 DOCM(启用宏的 DOCX):

System::SharedPtr<Document> doc = System::MakeObject<Document>(u"C:\\Temp\\in.doc");
doc->Save(u"C:\\Temp\\out.docm");