我能够将多个word文档合并到单个文档中,但我没有像多个word文档那样获得格式

时间:2013-11-08 07:57:27

标签: c#-4.0 ms-word

我正在尝试将6个单词文档合并到单个文档中,我能够合并所有六个文档,但我遇到了格式化和页眉和页脚的问题。

Word.Application objWordApp = new Word.Application();
Word.Document objWordDoc = new Word.Document();
object missing = Type.Missing;
object visible = true;
object objCreateDoc = "E:\\MergeTemplates\\Temp.doc";
string strNewDocPath1 = "E:\\MergeTemplates\\Templates\\Template1.doc";
string strNewDocPath2 = "E:\\MergeTemplates\\Templates\\Templates2.doc";
string strNewDocPath3 = "E:\\MergeTemplates\\Templates\\Template3.doc";
object objPageBreak = Word.WdBreakType.wdPageBreak;

try
{

    objWordDoc = objWordApp.Documents.Open(objCreateDoc, false, false, ref missing,
                                        ref missing, ref missing, ref missing, ref missing,
                                        ref missing, ref missing, ref missing, true,
                                        ref missing, ref missing, ref missing, ref missing);

    objWordDoc.Activate();
    objWordApp.Selection.InsertFile(strNewDocPath1, ref missing, true, ref missing, ref missing);
    objWordApp.Selection.InsertBreak(ref objPageBreak);
    objWordApp.Selection.InsertFile(strNewDocPath2, ref missing, ref missing, ref missing, ref missing);
    objWordApp.Selection.InsertBreak(ref objPageBreak);
    objWordApp.Selection.InsertFile(strNewDocPath3, ref missing, ref missing, ref missing, ref missing);
    objWordApp.Selection.InsertBreak(ref objPageBreak);
    objWordApp.ActiveDocument.SaveAs(objCreateDoc, ref missing, ref missing,
                                    ref missing, ref missing, ref missing, ref missing,
                                    ref missing,ref missing, ref missing, ref missing);
    objWordApp.ActiveDocument.Close(ref missing, ref missing, ref missing);
}

我正在尝试使用InsertFile()将多个word文档合并为单个word文档。

我可以合并它但字体和标题&页脚不匹配。我想要与多个文档中相同的格式。有没有办法让风格匹配?

1 个答案:

答案 0 :(得分:0)

尝试选择所有文档并从每个文档中复制并粘贴到新文档中