2009年4月21日 星期二

操作word檔案(四)-讀取舊檔內容

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();

IEnumerator ie = WordDoc.Paragraphs.GetEnumerator() ;
while(ie.MoveNext())
{
Microsoft.Office.Interop.Word.Paragraph para = (Microsoft.Office.Interop.Word.Paragraph)ie.Current ;
this.Label4.Text += para.Range.Text + "<br>" ;
}

WordApp.Application.Quit(ref Nothing, ref Nothing, ref Nothing);

沒有留言:

張貼留言