C # word 问题
我在三个word文档(test1.doc,test2.doc,test3.doc)里面分别放了三道题目( 题目1, 题目2, 题目3),我想把这三个文件里面的题目放到一个output.doc,我想得到的效果是:
(1)
题目1
(2)
题目2
(3)
题目3
但是我程序输出的是
题目1
题目2
题目3
(1)
(2)
(3)
我的代码在下面
public static void MergeDocoument()
{
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
string strTemplateName = HttpContext.Current.Server.MapPath("output.doc");
object falseValue = false;
object missing = System.Reflection.Missing.Value;
object TemplateFileName = strTemplateName;
Word.Application wordApp = new Word.ApplicationClass();
Word.Document wordDoc = wordApp.Documents.Add(ref missing, ref missing, ref
missing, ref missing);
wordDoc.Activate();
string strFileName=null;
for (int i = 1; i <= 3; i++)
{
Word.Paragraph oPara2;
object oRng = wordDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
oPara2 = wordDoc.Content.Paragraphs.Add(ref oRng);
oPara2.Range.Text = "(" + i.ToString() + ")";
oPara2.Format.SpaceAfter = 6;
oPara2.Range.InsertParagraphAfter();
strFileName = HttpContext.Current.Server.MapPath("test"+i.ToString()+".doc");
wordApp.Selection.InsertFile(strFileName, ref missing, ref falseValue, ref
falseValue, ref falseValue);
wordDoc.SaveAs(ref TemplateFileName, ref missing, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref
missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref
missing);
}
wordDoc.Close(ref missing, ref missing, ref missing);
wordApp.Quit(ref missing, ref missing, ref missing);
}