翻譯|使用教程|編輯:胡濤|2022-10-08 10:57:30.800|閱讀 210 次
概述:本文將介紹如何使用 C++ 將 DOCX 、DOC進行互相轉(zhuǎn)換,歡迎查閱~
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Aspose.Words 是一種高級Word文檔處理API,用于執(zhí)行各種文檔管理和操作任務(wù)。API支持生成,修改,轉(zhuǎn)換,呈現(xiàn)和打印文檔,而無需在跨平臺應(yīng)用程序中直接使用Microsoft Word。此外,API支持所有流行的Word處理文件格式,并允許將Word文檔導(dǎo)出或轉(zhuǎn)換為固定布局文件格式和最常用的圖像/多媒體格式。
Microsoft Word 文檔有兩種格式,DOC和DOCX。DOC 是一種較舊的格式,而 DOCX 是它的繼任者。您可以將 DOCX 文件轉(zhuǎn)換為 DOC 格式,反之亦然。在本文中,您將學(xué)習(xí)如何將 DOCX 文件轉(zhuǎn)換為 DOC 格式,以及將 DOCX 文件轉(zhuǎn)換為 DOCX 格式。您還將看到如何批量執(zhí)行這些轉(zhuǎn)換。
Aspose.Words for C++是一個本地 C++ 庫,允許您創(chuàng)建、閱讀和修改 Microsoft Word 文檔。此外,它還支持將 DOCX 文件轉(zhuǎn)換為 DOC 格式和將 DOC 文件轉(zhuǎn)換為 DOCX 格式。您可以通過NuGet安裝 API,也可以直接從“下載”部分下載。
PM> Install-Package Aspose.Words.Cpp
您可以按照以下步驟將 DOCX 文件轉(zhuǎn)換為 DOC 格式。
以下示例代碼展示了如何使用 C++ 將 DOCX 文件轉(zhuǎn)換為 DOC 文件。
// Create an instance of the LoadOptions class auto loadOptions = System::MakeObject<LoadOptions>(); // Specify LoadFormat of input word document loadOptions->set_LoadFormat(LoadFormat::Docx); // Load source DOCX file System::SharedPtr<Document> doc = System::MakeObject<Document>(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<LoadOptions>(); // Specify LoadFormat of input word document loadOptions->set_LoadFormat(LoadFormat::Docx); // Load the DOCX file System::SharedPtr<Document> doc = System::MakeObject<Document>((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<LoadOptions>(); // Specify LoadFormat of input word document loadOptions->set_LoadFormat(LoadFormat::Doc); // Load source DOC file System::SharedPtr<Document> doc = System::MakeObject<Document>(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<LoadOptions>(); // Specify LoadFormat of input word document loadOptions->set_LoadFormat(LoadFormat::Doc); // Load the DOC file System::SharedPtr<Document> doc = System::MakeObject<Document>((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); } }
以上便是使用 C++ 將 DOCX 和 DOC 進行互相轉(zhuǎn)換詳細步驟 ,要是您還有其他關(guān)于產(chǎn)品方面的問題,歡迎咨詢我們,或者加入我們官方技術(shù)交流群。
歡迎下載|體驗更多Aspose產(chǎn)品
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn