C#创建Word文档是我们经常在实际开发应用中碰到的实用性开发实例,那么具体的实现过程是什么呢?我们下面通过一个C#创建Word文档实例向你介绍具体的步骤。
C#创建Word文档实例:
- using MSExcel = Microsoft.Office.Interop.Excel;
- using System.IO;
- using System.Refletion;
- //C#创建Word文档
- Class Program
- {
- static void Main(string[] args)
- {
- string path; //C#创建Word文档之文件路径
- string strContent;//文本内容
- MSWord.Application wordApp;提要
- //C#创建Word文档之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文档有所帮助。
【编辑推荐】