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/

  • 相关阅读:
    基元线程同步构造之用户模式易变构造volatile
    C# 基元线程同步构造
    idea 的Low Memory问题
    python工具——xmind
    VSCODE 远程开发树莓派
    firefox临时文件位置及修改方法
    Veeam Backup & Replication 9.5 备份方式详解
    Windows下登录凭证密码获取工具
    VMProtect虚拟机保护分析入门
    Applescrip
  • 原文地址:https://www.cnblogs.com/jieyuefeng/p/3431427.html
Copyright © 2011-2022 走看看