object filename = Server.MapPath("WordTemplate") + "\\" + "Template2.doc" ; //開啟路徑
object readOnly = false;
object isVisible = true;
Object Nothing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.ApplicationClass WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Open(ref filename, ref Nothing,ref readOnly,
ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,
ref Nothing, ref Nothing, ref isVisible,ref Nothing,ref Nothing,ref Nothing,ref Nothing);
WordDoc.Activate();
//於現有內容的最前方加入內容
WordApp.Selection.TypeText("MicrosoftWord2003 第一行文字\n");
WordApp.Selection.TypeText("MicrosoftWord2003 第二行文字\n");
WordApp.Selection.TypeText("MicrosoftWord2003 第三行文字\n");
WordApp.Selection.TypeText("MicrosoftWord2003 第四行文字\n");
//於現有內容的最後方加入內容
WordDoc.Paragraphs.Last.Range.Text = "MicrosoftWord2003 最後行文字\n" ;
WordDoc.Save(); //存回原檔
WordApp.Application.Quit(ref Nothing, ref Nothing, ref Nothing);
this.Label2.Text = "< a href ='WordTemplate/"+ "Template2.doc" +"'> 查看產生的文件 </a>";
沒有留言:
張貼留言