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


     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/

  • 相关阅读:
    Win7停止更新升Win10教程
    linux 进程管理
    linux vi/Vim编辑器
    linux 文件管理
    linux 目录管理
    [开发笔记]-C#判断文件类型
    [开发笔记]-C#获取pdf文档的页数
    [转载]每周问问你的团队这10个问题
    [转载]番茄时间管理法(Pomodoro Technique):一个番茄是如何让你工作更有效率的
    [开发笔记]-Linq to xml学习笔记
  • 原文地址:https://www.cnblogs.com/jieyuefeng/p/3431427.html
Copyright © 2020-2023  润新知