Word Interop和C#,如何合并2个或更多文档? [英] Word Interop And C#, How to merge 2 or more documents?

查看:90
本文介绍了Word Interop和C#,如何合并2个或更多文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有以下问题.

我有两个文件

doc 1:

-----------------------
标头
-----------------------
内容内容内容
内容内容内容
内容内容内容
内容内容内容
内容内容内容
内容内容内容
-----------------------
页脚
-----------------------


Doc2
-----------------------
内容内容内容
内容内容内容
内容内容内容
内容内容内容
内容内容内容
内容内容内容
-----------------------

我需要的是:
-----------------------
标头
-----------------------
内容内容内容
内容内容内容
内容内容内容
内容内容内容
内容内容内容
内容内容内容
-----------------------
页脚
-----------------------
分页符
-----------------------
内容内容内容
内容内容内容
内容内容内容
内容内容内容
内容内容内容
内容内容内容
-----------------------

我有所有代码可以返回_documents或实际保存的文件.

我所需要的只是一些代码以合并它们,以达到预期的效果.

如果您有C#代码段或某些链接,我将不胜感激.

解决方案

检查这些不错的帖子

如何:合并C#中的多个Microsoft Word文档 [ C#教程-将多个Word文档合并为一个Word文档 [ ^ ]

尝试一下:

如何拆分和合并两个文件


大致内容的:

 pageSetup.HeaderDistance =  20 ;

  builder.MoveToHeaderFooter(HeaderFooterType.HeaderFirst);

  builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; 




这可能并不完美.根据需要进行调整.

--Vlad781


Hello Guys,

I have the following problem.

I have two documents

doc 1:

-----------------------
header
-----------------------
Content Content Content
Content Content Content
Content Content Content
Content Content Content
Content Content Content
Content Content Content
-----------------------
Footer
-----------------------


Doc2
-----------------------
Content Content Content
Content Content Content
Content Content Content
Content Content Content
Content Content Content
Content Content Content
-----------------------

What I need is:
-----------------------
header
-----------------------
Content Content Content
Content Content Content
Content Content Content
Content Content Content
Content Content Content
Content Content Content
-----------------------
Footer
-----------------------
page break
-----------------------
Content Content Content
Content Content Content
Content Content Content
Content Content Content
Content Content Content
Content Content Content
-----------------------

I have all the code to return to me either _documents or the actual saved files.

All I need is some code to merge them to give me the desired effect.

If you have a c# code snippet or some links I would truly appreciate it.

解决方案

Check these nice posts

How To: Merge Multiple Microsoft Word Documents in C#[^]
C# Tutorial - Combine Multiple Word Documents into One Word Document [^]


Try this :

How to Split and Merge Two Files


Something along the lines of:

pageSetup.HeaderDistance = 20;

  builder.MoveToHeaderFooter(HeaderFooterType.HeaderFirst);

  builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;




This may not be perfect. Adjust as needed.

--Vlad781


这篇关于Word Interop和C#,如何合并2个或更多文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆