C#创建Word文档实例解析

开发 后端
C#创建Word文档的具体实现是怎么样子的呢?C#创建Word文档需要用到什么方法呢?那么本文就向你介绍具体的实例实现,希望对你的学习有所帮助。

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文档  
}   
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.

C#创建Word文档的基本内容和实现实例就向你介绍到这里,希望对你了解和学习C#创建Word文档有所帮助。

【编辑推荐】

  1. 详解C#读取word内容操作
  2. C#读取Word文件实例详解
  3. C#读取Word学习经验总结
  4. 浅析C#打开Word文档实例
  5. 浅析C#Word文档替换操作
责任编辑:仲衡 来源: CSDN博客
相关推荐

2009-08-28 17:34:14

读取word文档

2009-09-01 13:13:28

C#打开Word文档

2009-08-28 17:46:18

C#读取Word文档

2009-09-02 16:14:21

C#动态创建数组

2009-08-19 10:16:15

C#操作Word

2009-09-09 14:40:15

C# XML解析

2009-08-19 09:42:52

C#操作Word书签

2009-08-19 11:13:49

C#操作Word

2009-08-19 11:34:06

C#操作Word

2009-09-01 11:25:08

C#读取Word文件

2009-08-18 10:47:40

C#枚举类型

2009-09-09 13:57:28

C# XML解析

2009-08-24 17:24:28

C#创建XML文档

2009-08-31 18:17:32

C#接口编程

2009-09-07 06:31:32

C#窗体移动

2009-08-19 16:09:15

C#操作Access

2009-08-26 12:14:44

C#打印设置

2009-08-12 15:26:38

C#读取XML文档

2009-08-26 11:32:37

C#打印文档

2009-08-19 11:28:41

C#操作Word
点赞
收藏

51CTO技术栈公众号