Word.ApplicationClass word=new Microsoft.Office.Interop.Word.ApplicationClass();
   Type wordType=word.GetType();
   Word.Documents docs=word.Documents;

   word.Visible=true;
   // 打开文件
   //Type docsType=docs.GetType();
   //object fileName="c:\\test.doc";
   //Word.Document doc=(Word.Document)docsType.InvokeMember("Open",System.Reflection.BindingFlags.InvokeMethod,null,docs,new object[]{fileName,true,false});
   //doc.Content.InsertAfter("This is a comment"); // 在文后增加内容
   //MessageBox.Show(this,doc.Content.get_XML(false)); //得到文档的XML

   

   // 新建文件
   Type docsType=docs.GetType();
   
   object template="c:\\test.dot";
   object newTemplate=Missing.Value;
   object documentType=Missing.Value;
   object visible=true;
   Word.Document doc=(Word.Document)docsType.InvokeMember("Add",System.Reflection.BindingFlags.InvokeMethod,null,docs,new object[]{template,newTemplate,documentType,visible});
   doc.XMLNodes[1].SelectSingleNode("/n:Person/n:Name","xmlns:n='http://tempuri.org/test.xsd'",true).Text=textBox1.Text;
   doc.XMLNodes[1].SelectSingleNode("/n:Person/n:Age","xmlns:n='http://tempuri.org/test.xsd'",true).Text=textBox2.Text;

Posted on 2005-05-04 21:08  RichardChoi  阅读(957)  评论(2)    收藏  举报