Word控件Spire.Doc 【文档操作】教程(十):在 C# 中通过分节符将 Word 文档拆分为多个文档

详细步骤和代码片段:

第 1步初始化一个新的word文档对象并加载包含两个部分的原始word文档。

Document document = new Document();document.LoadFromFile("Test.docx");

第 2 步定义另一个新的 word 文档对象。

Document newWord;

第 3 步遍历原word文档的所有section,将每个section克隆并作为新的section添加到一个新的word文档中,然后将文档保存到指定路径。

for (int i = 0; i < document.Sections.Count; i++){newWord = new Document();newWord.Sections.Add(document.Sections[i].Clone());newWord.SaveToFile(String.Format(@"testout_{0}.docx", i));}

运行项目,我们将得到以下输出:

如何在 C# 中通过分节符将 Word 文档拆分为多个文档

完整代码

using System;using Spire.Doc;namespace Split_Word_Document{class Program{static void Main(string[] args){Document document = new Document();document.LoadFromFile("Test.doc");Document newWord;for (int i = 0; i < document.Sections.Count; i++){newWord = new Document();newWord.Sections.Add(document.Sections[i].Clone());newWord.SaveToFile(String.Format(@"testout_{0}.docx", i));}}}}

欢迎下载|体验更多E-iceblue产品

如需获取更多产品相关信息请咨询在线客服  

aspose22.1最新版

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2022年3月10日
下一篇 2022年3月10日

相关推荐

发表回复

登录后才能评论