使用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);
}
}
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#在word文档中创建表格的方法详解
- 使用c#读取word文档
- 如何使用C#从word文档中提取图片
- C#程序通过模板自动创建Word文档
- C#对Word文档的创建、插入表格、设置样式等操作实例
- C#实现通过模板自动创建Word文档的方法
- 使用 Word 2007 和 Visual Basic 2005 自动创建数据丰富的业务文档
- 使用C#创建PowerPoint文档
- 使用Docx4j创建word文档
- C# 中使用Word文档对图像进行操作
- 使用C#替换Word文档里的文字和图片
- 使用docx4j编程式地创建复杂的Word(.docx)文档
- C# 中使用Word文档对图像进行操作
- C#创建Word文档
- C#程序通过模板自动创建Word文档
- C#实现通过模板自动创建Word文档的方法
- C#中使用FlashPrinter将WORD文档转成PDF或者SWF
- 如何使用C#在Word文档中插入图片以及读取Word文档中的图片?
- 使用C#创建Excel文档
- 使用C#在Excel文档中创建图表