翻譯|使用教程|編輯:李顯亮|2021-03-04 10:24:41.687|閱讀 289 次
概述:MS Word是用于存儲和共享信息的流行格式。在某些情況下,想將Word文檔拆分為多個文件。在本文中,將學習 如何使用C ++拆分MS Word文檔。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
MS Word是用于存儲和共享信息的流行格式。在某些情況下,想將Word文檔拆分為多個文件。例如,文檔可能包含需要與不同人員共享的不同部分,或者包含一些需要分開的機密信息。在這種情況下,拆分Word文檔被證明是有幫助的。在本文中,將學習 如何使用C ++拆分MS Word文檔。
Aspose.Words for C ++是本機C ++庫,允許您生成,更改和轉換Microsoft Word文檔。此外,它還支持將Word文檔拆分為多個文件。
如果你還沒有用過C ++版Aspose.Words可以點擊這里下載最新版測試。
以下是使用C ++拆分Word文件的步驟。
以下是用于按頁面拆分Word文檔的示例代碼。
// Sample Word document System::String sampleFile = u"SourceDirectory\\Sample 3.docx"; // Load the Word document System::SharedPtrdocument = System::MakeObject(sampleFile); // Create and initialize document page splitter DocumentPageSplitter splitter = DocumentPageSplitter(document); // Output file path System::String outputPath = u"OutputDirectory\\"; // Save each page as a separate document for (int page = 1; page <= document->get_PageCount(); page++) { auto pageDoc = splitter.GetDocumentOfPage(page); pageDoc->Save(outputPath + u"SplitDocumentPageByPageOut_" + System::Convert::ToString(page) + u".docx"); }
除了分隔每個頁面,您還可以通過提供頁面范圍來拆分Word文檔。以下是使用頁面范圍拆分Word文檔的步驟。
以下是用于使用頁面范圍拆分Word文檔的示例代碼。
// Sample Word document System::String sampleFile = u"SourceDirectory\\Sample 3.docx"; // Load the Word document System::SharedPtrdocument = System::MakeObject(sampleFile); // Create and initialize document page splitter DocumentPageSplitter splitter = DocumentPageSplitter(document); // Get the page range auto pageDoc = splitter.GetDocumentOfPageRange(2, 3); // Output file path System::String outputPath = u"OutputDirectory\\"; // Save as DOCX file pageDoc->Save(outputPath + u"SplitDocumentByPageRangeOut.docx");
Word文件可以包含一個或多個部分,這些部分可能具有不同的格式,并且可以由任意數量的頁面組成。要在Word文件中添加新部分,請使用Layout> Breaks> Section Breaks選項。以下是使用Aspose.Words for C ++ API按部分拆分Word文件的步驟。
下面是示例代碼,用于按部分拆分Word文檔。
// Sample Word document System::String sampleFile = u"SourceDirectory\\Sample 3.docx"; // Load the Word document System::SharedPtrdocument = System::MakeObject(sampleFile); // Output file path System::String outputPath = u"OutputDirectory\\"; for (int i = 0; i < document->get_Sections()->get_Count(); i++) { // Split a document into smaller parts, in this instance split by section auto section = document->get_Sections()->idx_get(i)->Clone(); // Create a new document auto newDoc = System::MakeObject(); newDoc->get_Sections()->Clear(); //Add new section to the newly created document auto newSection = System::StaticCast(newDoc->ImportNode(section, true)); newDoc->get_Sections()->Add(newSection); // Save each section as a separate document newDoc->Save(outputPath + u"SplitDocumentBySectionsOut_" + System::Convert::ToString(i) + u".docx"); }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn