翻譯|使用教程|編輯:胡濤|2022-11-10 10:10:27.987|閱讀 277 次
概述:在本文中,您將學(xué)習(xí)如何使用 C++ 合并多個 MS Word 文檔。
# 界面/圖表報表/文檔/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)換為固定布局文件格式和最常用的圖像/多媒體格式。
MS Word 是一個強大的工具,它允許您使用一組出色的功能自定義和格式化您的專業(yè)文檔。您可能會發(fā)現(xiàn)自己需要合并多個 Word 文檔,例如將所有收據(jù)合并到一個文件中,或者合并不同的軟件需求文檔以便于管理。此外,合并文件簡化了共享它們的過程。在本文中,您將學(xué)習(xí)如何使用 C++ 合并多個 MS Word 文檔。
Aspose.Words for C++是一個原生 C++ 庫,允許您創(chuàng)建、更改和轉(zhuǎn)換 Microsoft Word 文檔。此外,它還支持將多個 Word 文檔合并到一個文件中。您可以通過NuGet安裝 API,也可以直接從“下載”部分下載。
PM> Install-Package Aspose.Words.Cpp
將 Word 文檔與 Aspose.Words for C++ API 合并是一件輕而易舉的事。您只需幾行代碼即可加載和合并它們。下圖顯示了我們將在本文中合并的兩個示例 Word 文件。
以下是使用 C++ 合并 Word 文檔的步驟。
以下是合并 Word 文檔的示例代碼。
// Sample Word documents to be merged System::String sampleFile1 = u"SourceDirectory\\Sample 1.docx"; System::String sampleFile2 = u"SourceDirectory\\Sample 2.docx"; // Load Word documents to be merged System::SharedPtr<Aspose::Words::Document> document1 = System::MakeObject<Aspose::Words::Document>(sampleFile1); System::SharedPtr<Aspose::Words::Document> document2 = System::MakeObject<Aspose::Words::Document>(sampleFile2); // Merge documents keeping source file's formatting document1->AppendDocument(document2, Aspose::Words::ImportFormatMode::KeepSourceFormatting); // Output file path System::String outputPath = u"OutputDirectory\\merged-doc-out.docx"; // Save merged document as DOCX file document1->Save(outputPath, Aspose::Words::SaveFormat::Docx);
下圖比較了使用 ::KeepSourceFormatting 和ImportFormatMode ::UseDestinationStyles 模式生成的合并文檔。
使用ImportFormatMode::KeepSourceFormatting生成的輸出
使用ImportFormatMode::UseDestinationStyles生成的輸出
Aspose.Words for C++ API 提供ImportFormatOptions類用于自定義 Word 文件的合并。以下是ImportFormatOptions類提供的選項。
以下是將多個 Word 文檔與其他選項合并的步驟:
以下是使用附加選項合并 Word 文檔的示例代碼。
// Sample Word documents to be merged System::String sampleFile1 = u"SourceDirectory\\Sample 1.docx"; System::String sampleFile2 = u"SourceDirectory\\Sample 2.docx"; // Load Word documents to be merged System::SharedPtr<Aspose::Words::Document> document1 = System::MakeObject<Aspose::Words::Document>(sampleFile1); System::SharedPtr<Aspose::Words::Document> document2 = System::MakeObject<Aspose::Words::Document>(sampleFile2); // Set options auto options = MakeObject<Aspose::Words::ImportFormatOptions>(); options->set_IgnoreHeaderFooter(false); // Merge documents keeping source file's formatting document1->AppendDocument(document2, Aspose::Words::ImportFormatMode::KeepSourceFormatting, options); // Output file path System::String outputPath = u"OutputDirectory\\merged-doc-out.docx"; // Save merged document as DOCX file document1->Save(outputPath, Aspose::Words::SaveFormat::Docx);
下圖比較了通過將IgnoreHeaderFooter選項設(shè)置為true和false生成的合并文檔。
通過將IgnoreHeaderFooter選項設(shè)置為true生成的輸出
通過將IgnoreHeaderFooter選項設(shè)置為false生成的輸出
以上便是使用 C++ 合并 MS Word 文檔詳細步驟 ,要是您還有其他關(guān)于產(chǎn)品方面的問題,歡迎咨詢我們,或者加入我們官方技術(shù)交流群。
歡迎下載|體驗更多Aspose產(chǎn)品
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn