翻譯|使用教程|編輯:李顯亮|2021-06-29 11:05:38.640|閱讀 328 次
概述:在本文中,將學(xué)習(xí)如何將 DOCX 文件轉(zhuǎn)換為 DOC 格式以及如何將 DOC 文件轉(zhuǎn)換為 DOCX 格式。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Microsoft Word 文檔有兩種格式, DOC 和 DOCX。DOC 是一種較舊的格式,而 DOCX 是它的繼任者??梢詫?DOCX 文件轉(zhuǎn)換為 DOC 格式,反之亦然。在本文中,將學(xué)習(xí)如何將 DOCX 文件轉(zhuǎn)換為 DOC 格式以及如何將 DOC 文件轉(zhuǎn)換為 DOCX 格式。
讓我們探索以下有關(guān)的內(nèi)容:
Aspose.Words for C++ 是一個原生的 C++ 庫,允許您創(chuàng)建、讀取和修改 Microsoft Word 文檔。此外,它還支持將 DOCX 文件轉(zhuǎn)換為 DOC 格式和將 DOC 文件轉(zhuǎn)換為 DOCX 格式。
>>你可以點擊這里下載Aspose.Words for C ++ 最新版測試體驗。
可以按照以下步驟將 DOCX 文件轉(zhuǎn)換為 DOC 格式。
以下示例代碼顯示了如何使用 C++ 將 DOCX 文件轉(zhuǎn)換為 DOC 文件。
// Create an instance of the LoadOptions class auto loadOptions = System::MakeObject(); // Specify LoadFormat of input word document loadOptions->set_LoadFormat(LoadFormat::Docx); // Load source DOCX file System::SharedPtrdoc = System::MakeObject(u"SourceDirectory\\Word\\Sample 4.docx", loadOptions); // Save the DOC file doc->Save(u"OutputDirectory\\output.doc", SaveFormat::Doc);
如果有數(shù)百個 DOCX 文件需要轉(zhuǎn)換為 DOC 格式,則只需執(zhí)行一次程序即可輕松轉(zhuǎn)換它們。在這個例子中,我們將使用 boost 庫來遍歷目錄中的文件。以下是將DOCX文件批量轉(zhuǎn)換為DOC格式的步驟。
以下示例代碼演示了如何使用 C++ 將 DOCX 文件批量轉(zhuǎn)換為 DOC 格式。
// Iterate through the files in the directory for (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); } }
以下是將 DOC 文件轉(zhuǎn)換為 DOCX 文件的步驟。
以下示例代碼顯示了如何使用 C++ 將 DOC 文件轉(zhuǎn)換為 DOCX 文件。
// Create an instance of the LoadOptions class auto loadOptions = System::MakeObject(); // Specify LoadFormat of input word document loadOptions->set_LoadFormat(LoadFormat::Doc); // Load source DOC file System::SharedPtrdoc = System::MakeObject(u"SourceDirectory\\Word\\Sample 1.doc", loadOptions); // Save the DOCX file doc->Save(u"OutputDirectory\\output.docx", SaveFormat::Docx);
要將 DOC 文件批量轉(zhuǎn)換為 DOCX 格式,請使用以下步驟。
以下示例代碼演示了如何使用 C++ 將 DOC 文件批量轉(zhuǎn)換為 DOCX 格式。
// Iterate through the files in the directory for (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的全部完整功能,可聯(lián)系在線客服獲取30天臨時授權(quán)體驗。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn