• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C#生成带项目编号的Word段落

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
 1 using System;
 2 using Microsoft.Office.Interop.Word;
 3 using Word = Microsoft.Office.Interop.Word;
 4 namespace WordList
 5 {
 6     class WordList
 7     {
 8         static void Main(string[] args)
 9         {
10             string message = "";
11             try
12             {
13                 Object Nothing = System.Reflection.Missing.Value;
14                 object filename = "d://WordList.doc";
15                 Word.Application app = new Word.ApplicationClass();
16                 Word.Document doc = app.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
17 
18                 doc.Paragraphs[1].Range.Text = "段落一";
19 
20                 doc.Paragraphs.Add(ref Nothing);
21                 doc.Paragraphs[2].Range.Text = "段落二";
22 
23                 doc.Paragraphs.Add(ref Nothing);
24                 doc.Paragraphs[3].Range.Text = "段落三";
25 
26                 doc.Paragraphs.Add(ref Nothing);
27                 doc.Paragraphs[4].Range.Text = "段落四";
28 
29 
30                 object i = 1;
31                 object t = true;
32                 Word.ListTemplate listTemp = app.ListGalleries[Word.WdListGalleryType.wdBulletGallery].ListTemplates.get_Item(ref i);
33                 app.ActiveDocument.Paragraphs[1].Range.ListFormat.ApplyListTemplate(listTemp, ref t, ref Nothing, ref Nothing);
34                 app.ActiveDocument.Paragraphs[2].Range.ListFormat.ApplyListTemplate(listTemp, ref t, ref Nothing, ref Nothing);
35                 app.ActiveDocument.Paragraphs[3].Range.ListFormat.ApplyListTemplate(listTemp, ref t, ref Nothing, ref Nothing);
36                 app.ActiveDocument.Paragraphs[4].Range.ListFormat.ApplyListTemplate(listTemp, ref t, ref Nothing, ref Nothing);
37 
38                 doc.SaveAs(ref filename, 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, ref Nothing);
39                 doc.Close(ref Nothing, ref Nothing, ref Nothing);
40                 app.Quit(ref Nothing, ref Nothing, ref Nothing);
41                 message = "文档生成成功";
42             }
43             catch (Exception e)
44             {
45                 message = "文件导出异常!" + e;
46             }
47 
48             Console.WriteLine(message);
49         }
50     }
51 }

 

不懂c#所以先记下来

参考:

http://www.cnblogs.com/yuxia/archive/2013/07/31/3227503.html

http://blog.sina.com.cn/s/blog_533506c10100ax8w.html

感谢:

http://q.cnblogs.com/q/57022/


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#CacheHelper发布时间:2022-07-14
下一篇:
C#把数组转换成DataSet数据类型发布时间:2022-07-14
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap