让我们探索以下有关的内容:
- 使用 C++ 将 DOCX 文件转换为 DOC 格式
- 使用 C++ 将 DOCX 文件批量转换为 DOC 格式
- 使用 C++ 将 DOC 文件转换为 DOCX 格式
- 使用 C++ 将 DOC 文件批量转换为 DOCX 格式

Aspose.Words for C++ 是一个原生的 C++ 库,允许您创建、读取和修改 Microsoft Word 文档。此外,它还支持将 DOCX 文件转换为 DOC 格式和将 DOC 文件转换为 DOCX 格式。
>>你可以点击这里下载Aspose.Words for C ++ 最新版测试体验。
使用 C++ 将 DOCX 文件转换为 DOC 格式
可以按照以下步骤将 DOCX 文件转换为 DOC 格式。
- 创建LoadOptions类的实例。
- 使用LoadOptions->set_LoadFormat(Aspose::Words::LoadFormat value)方法将加载格式设置为 DOCX 。
- 使用Document 类加载源 DOCX 文件 。
- 使用Document->Save(System::String fileName, Aspose::Words::SaveFormat saveFormat)方法保存转换后的 DOC 文件。
以下示例代码显示了如何使用 C++ 将 DOCX 文件转换为 DOC 文件。
// Create an instance of the LoadOptions classauto loadOptions = System::MakeObject();// Specify LoadFormat of input word documentloadOptions->set_LoadFormat(LoadFormat::Docx);// Load source DOCX fileSystem::SharedPtrdoc = System::MakeObject(u"SourceDirectory\Word\Sample 4.docx", loadOptions);// Save the DOC filedoc->Save(u"OutputDirectory\output.doc", SaveFormat::Doc);
使用 C++ 将 DOCX 文件批量转换为 DOC 格式
如果有数百个 DOCX 文件需要转换为 DOC 格式,则只需执行一次程序即可轻松转换它们。在这个例子中,我们将使用 boost 库来遍历目录中的文件。以下是将DOCX文件批量转换为DOC格式的步骤。
- 遍历目录中的文件。
- 创建LoadOptions类的实例。
- 使用LoadOptions->set_LoadFormat(Aspose::Words::LoadFormat value)方法将加载格式设置为 DOCX 。
- 使用Document 类加载 DOCX 文件。
- 将文件名中的扩展名更改为 DOC。
- 使用Document->Save(System::String fileName, Aspose::Words::SaveFormat saveFormat)方法保存转换后的 DOC 文件。
以下示例代码演示了如何使用 C++ 将 DOCX 文件批量转换为 DOC 格式。
// Iterate through the files in the directoryfor (directory_entry& file : directory_iterator("SourceDirectory\Word")){ // Check file extension if (file.path().extension().string() == ".docx") { // Create an instance of the LoadOptions class auto loadOptions = System::MakeObject(); // Specify LoadFormat of input word document loadOptions->set_LoadFormat(LoadFormat::Docx); // Load the DOCX file System::SharedPtrdoc = System::MakeObject((System::String)file.path().string(), loadOptions); // Change the file extension System::String fileName = (System::String)file.path().filename().string(); fileName = fileName.Replace(u".docx", u".doc"); // Save the DOC file doc->Save(System::String::Concat(u"OutputDirectory\", fileName), SaveFormat::Doc); }}
使用 C++ 将 DOC 文件转换为 DOCX 格式
以下是将 DOC 文件转换为 DOCX 文件的步骤。
- 创建LoadOptions类的实例。
- 使用LoadOptions->set_LoadFormat(Aspose::Words::LoadFormat value)方法将加载格式设置为 DOC 。
- 使用Document 类加载源 DOC 文件 。
- 使用Document->Save(System::String fileName, Aspose::Words::SaveFormat saveFormat)方法保存转换后的 DOCX 文件。
以下示例代码显示了如何使用 C++ 将 DOC 文件转换为 DOCX 文件。
// Create an instance of the LoadOptions classauto loadOptions = System::MakeObject();// Specify LoadFormat of input word documentloadOptions->set_LoadFormat(LoadFormat::Doc);// Load source DOC fileSystem::SharedPtrdoc = System::MakeObject(u"SourceDirectory\Word\Sample 1.doc", loadOptions);// Save the DOCX filedoc->Save(u"OutputDirectory\output.docx", SaveFormat::Docx);
使用 C++ 将 DOC 文件批量转换为 DOCX 格式
要将 DOC 文件批量转换为 DOCX 格式,请使用以下步骤。
- 遍历目录中的文件。
- 创建LoadOptions类的实例。
- 使用LoadOptions->set_LoadFormat(Aspose::Words::LoadFormat value)方法将加载格式设置为 DOC 。
- 使用Document 类加载 DOC 文件。
- 将文件名中的扩展名更改为 DOCX。
- 使用Document->Save(System::String fileName, Aspose::Words::SaveFormat saveFormat)方法保存转换后的 DOCX 文件。
以下示例代码演示了如何使用 C++ 将 DOC 文件批量转换为 DOCX 格式。
// Iterate through the files in the directoryfor (directory_entry& file : directory_iterator("SourceDirectory\Word")){ // Check file extension if (file.path().extension().string() == ".doc") { // Create an instance of the LoadOptions class auto loadOptions = System::MakeObject(); // Specify LoadFormat of input word document loadOptions->set_LoadFormat(LoadFormat::Doc); // Load the DOC file System::SharedPtrdoc = System::MakeObject((System::String)file.path().string(), loadOptions); // Change the file extension System::String fileName = (System::String)file.path().filename().string(); fileName = fileName.Replace(u".doc", u".docx"); // Save the DOCX file doc->Save(System::String::Concat(u"OutputDirectory\", fileName), SaveFormat::Docx); }}
如果你想试用Aspose的全部完整功能,可联系在线客服获取30天临时授权体验。
还想要更多吗可以点击阅读【Aspose最新资源在线文库】,查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询。
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!