zoukankan      html  css  js  c++  java
  • 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/

  • 相关阅读:
    3.14周末作业
    3.13作业
    文件处理
    字符编码
    基本数据类型总结
    基本数据类型--------------------集合set()
    python入门009
    作业009
    python入门008
    作业008
  • 原文地址:https://www.cnblogs.com/jieyuefeng/p/3431427.html
Copyright © 2011-2022 走看看