none
怎么用C#在Word里设置"标题1","标题2"等格式啊? RRS feed

答案

  • 您好,

    根据你的描述, 我想你可以参考下如下的代码:

    ApplicationClass WordApp = new ApplicationClass();
    // open the document specified in the fileName variable
    Document adoc = WordApp.Documents.Open(ref fileName, ref missing, ref missing, ref missing, ref missing,ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,ref missing, ref missing, ref missing);
    
    Range myRange = adoc.Range(ref missing, ref missing);
    myRange.InsertAfter(“Test“);
    object oStyleName = “Heading 1″;
    myRange.set_Style(ref oStyleName);

    上述代码是插入一个标题“Test”, 并把它的格式设置为“Heading 1”。


    Vin Jin [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • 已标记为答案 Aspen VJ 2011年7月6日 1:28
    2011年6月29日 2:49