没有合适的资源?快使用搜索试试~ 我知道了~
首页C#调用word的实现
C#调用word的实现
需积分: 15 27 下载量 181 浏览量
更新于2023-07-20
收藏 128KB DOC 举报
C#调用word的实现 要使用C#操作word,首先要添加引用: 1、添加引用->COM->Microsoft Word 11.0 Object Library 2、在.cs文件中添加
资源详情
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/1132416/bg1.jpg)
要使用 C#操作 word,首先要添加引用:
1、添加引用->COM->Microsoft Word 11.0 Object Library
2、在.cs 文件中添加
usingWord;
下面的例子中包括 C#对 Word 文档的创建、插入表格、设置样式等操作:
(例子中代码有些涉及数据信息部分被省略,重要是介绍一些 C#操作 word 文档的方法)
publicstringCreateWordFile(stringCheckedInfo)
{
stringmessage="";
try
{
ObjectNothing=System.Reflection.Missing.Value;
Directory.CreateDirectory("C:/CNSI");//创建文件所在目录
stringname="CNSI_"+DateTime.Now.ToShortString()+".doc";
objectfilename="C://CNSI//"+name;//文件保存路径
//创建 Word 文档
Word.ApplicationWordApp=newWord.ApplicationClass();
Word.DocumentWordDoc=WordApp.Documents.Add(refNothing,refNothing,refNothing,
refNothing);
//添加页眉
WordApp.ActiveWindow.View.Type=WdViewType.wdOutlineView;
WordApp.ActiveWindow.View.SeekView=WdSeekView.wdSeekPrimaryHeader;
WordApp.ActiveWindow.ActivePane.Selection.InsertAfter("[页眉内容]");
WordApp.Selection.ParagraphFormat.Alignment=Word.WdParagraphAlignment.wdAlignP
aragraphRight;//设置右对齐
WordApp.ActiveWindow.View.SeekView=WdSeekView.wdSeekMainDocument;//跳出页眉
设置
WordApp.Selection.ParagraphFormat.LineSpacing=15f;//设置文档的行间距
//移动焦点并换行
objectcount=14;
objectWdLine=Word.WdUnits.wdLine;//换一行;
WordApp.Selection.MoveDown(refWdLine,refcount,refNothing);//移动焦点
WordApp.Selection.TypeParagraph();//插入段落
//文档中创建表格
Word.TablenewTable=WordDoc.Tables.Add(WordApp.Selection.Range,12,3,refNothin
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://profile-avatar.csdnimg.cn/c24dfdfe2d674e1c9fa6737b48be0bb3_kikaylee.jpg!1)
kikay
- 粉丝: 155
- 资源: 20
上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![](https://csdnimg.cn/release/wenkucmsfe/public/img/voice.245cc511.png)
会员权益专享
最新资源
- BSC绩效考核指标汇总 (2).docx
- BSC资料.pdf
- BSC绩效考核指标汇总 (3).pdf
- C5000W常见问题解决方案.docx
- BSC概念 (2).pdf
- ESP8266智能家居.docx
- ESP8266智能家居.pdf
- BSC概念 HR猫猫.docx
- C5000W常见问题解决方案.pdf
- BSC模板:关键绩效指标示例(财务、客户、内部运营、学习成长四个方面).docx
- BSC概念.docx
- BSC模板:关键绩效指标示例(财务、客户、内部运营、学习成长四个方面).pdf
- BSC概念.pdf
- 各种智能算法的总结汇总.docx
- BSC概念 HR猫猫.pdf
- bsc概念hr猫猫.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![](https://csdnimg.cn/release/wenkucmsfe/public/img/green-success.6a4acb44.png)