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/

  • 相关阅读:
    Python类属性的延迟计算
    解析Python编程中的包结构
    解析Python编程中的包结构
    Python查询Mysql时返回字典结构的代码
    VS2010中如何查看DLL的导出接口
    C++ 简单的日志类
    ilmerge工具合并多个DLL或EXE
    基于InstallShield2013LimitedEdition的安装包制作
    c# 操作注册表
    Source Insight 常用设置和快捷键大全
  • 原文地址:https://www.cnblogs.com/jieyuefeng/p/3431427.html
Copyright © 2011-2022 走看看