
用于将 PowerPoint 文件转换为 Word 格式的 C++ API
为了将 PowerPoint 演示文稿转换为 Word 文档,我们将使用Aspose.Slides for C++和Aspose.Words for C++ APIs。前者是用于处理 PowerPoint 文件的 API,而后者用于创建、读取和修改 Word 文档。我们将使用 Aspose.Slides for C++ API 将 PowerPoint 文件转换为 HTML 格式,并使用 Aspose.Words for C++ API 将生成的 HTML 转换为 Word 格式。您可以通过 NuGet 安装 API,也可以直接从“下载”部分下载它们。
PM> Install-Package Aspose.Slides.CppPM> Install-Package Aspose.Words.Cpp
使用 C++ 将 PowerPoint PPTX/PPT 文件转换为 DOCX 格式
以下是使用 C++ 将 PowerPoint PPTX/PPT 文件转换为 DOCX 格式的步骤。
- 使用Aspose::Slides::Presentation类加载 PowerPoint 文件。
- 创建MemoryStream类的实例。
- 将演示文稿保存到流中。
- 使用流对象创建Aspose::Words::Document类的实例。
- 使用Aspose::Words::Document->Save(const System::String & fileName, Aspose::Words::SaveFormat saveFormat)方法保存 DOCX 文件。
以下示例代码展示了如何使用 C++ 将 PowerPoint PPTX/PPT 文件转换为 DOCX 格式。
// File pathsconst String sourceFilePath = u"SourceDirectory\Slides\SamplePresentation.pptx";const String outputFilePath = u"OutputDirectory\SlidesToWord_out.docx";// Load the presentation fileauto presentation = System::MakeObject<Aspose::Slides::Presentation>(sourceFilePath);// Create an instance of the MemoryStream classauto stream = System::MakeObject<MemoryStream>();// Save the presentation to the streampresentation->Save(stream, SaveFormat::Html);stream->Flush();stream->Seek(0, SeekOrigin::Begin);// Create an instance of the Document class using the streamauto doc = System::MakeObject<Aspose::Words::Document>(stream);// Save the Word documentdoc->Save(outputFilePath, Aspose::Words::SaveFormat::Docx);
结论
欢迎下载|体验更多Aspose产品
获取更多信息请咨询在线客服 或 加入Aspose技术交流群()
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!