使用C#创建Word文档

using MSExcel = Microsoft.Office.Interop.Excel;

using System.IO;

using System.Refletion;

Class Program

{

  static void Main(string[] args)

  {

    string path;      //文件路径

    string strContent;    //文本内容

    MSWord.Application wordApp;提要   //word应用程序

    MSWord.document wordDoc;    //word文档

    path = @"c:/test.docx";

    wordApp = new MSWord.applicationClass();

    if(File.Exists(path))

    {

      File.Delete(path);

    }

    Object nothing = Missing.Value;

    wordDoc = wordApp.Documents.Add(ref nothing,ref nothing,ref nothing,ref nothing);

    strContent = "你好!/n";

    wordDoc.Paragraphs.Last.Rang.Text = strContent;

    object format = MSWord.WdSaveFormat.wdFormatDocumentDefault;

    wordDoc.SaveAs(ref path,ref format,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,

              ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,

             ref nothing,ref nothing,ref nothing);

    wordDoc.Close(ref nothing,ref nothing,ref nothing);

    wordApp.Quit(ref nothing,ref nothing,ref nothing);

  }

你可能感兴趣的:(c,String,object,C#,文档,Path)