1、添加word引用,并引入命名空间 using Microsoft.Office.Interop.Word;(并不需要引用office.dll的)
2、往word里写入文字:
object fileName =Server.MapPath("test.doc");
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
ApplicationClass oWordApp = new ApplicationClass();
Document oWordDoc = oWordApp.Documents.Open(ref fileName, ref missing, ref readOnly,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing);
//oWordDoc.Activate();
oWordApp.Selection.TypeText("测试");
oWordApp.Selection.TypeParagraph();
oWordDoc.Save();
oWordApp.Application.Quit(ref missing, ref missing, ref missing);