您的位置:首页 > 编程语言 > C#

使用C#创建Word文档

2008-04-18 22:44 676 查看
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);

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: