在使用MS Word时,用户可以点击“插入”-“对象”-“文件中的文字”快速将选定文件中的文本插入当前文档。

添加新页合并
/获取文档路径string filePath_1 = @"C:UsersAdministratorDesktopWord_1.docx";string filePath_2 = @"C:UsersAdministratorDesktopWord_2.docx";//加载文档1到Document对象Document doc= new Document(filePath_1);//使用InsertTextFromFile方法将文档2合并到新文档doc.InsertTextFromFile(filePath_2, FileFormat.Docx2013);//保存文档doc.SaveToFile("合并文档.docx", FileFormat.Docx2013);

承接前一个文档的段尾合并
//初始化两个Document实例并加载两个测试文档Document doc1 = new Document(@"C:UsersAdministratorDesktop测试文档_1.docx");Document doc2 = new Document(@"C:UsersAdministratorDesktop测试文档_2.docx");//获取doc1的最后一个sectionSection lastSection = doc1.LastSection;//遍历doc2的section和段落,将每一个段落添加到doc1的最后一个sectionforeach (Section section in doc2.Sections){ foreach (Paragraph paragraph in section.Paragraphs) { lastSection.Paragraphs.Add(paragraph.Clone() as Paragraph); }}//保存为新的文档doc1.SaveToFile("合并文档_2.docx", FileFormat.Docx2013);

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