详细步骤和代码片段:
第 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));}
运行项目,我们将得到以下输出:

完整代码:
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产品
如需获取更多产品相关信息请咨询在线客服
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!