使用编号自定义 Microsoft Word built-in 样式

Customize Microsoft Word built-in style with numbering

我有一个 word 文档,其中已经定义了盛装 built-in 样式。如下图。

我想通过 运行 下面的 C# 代码更改预定义 built-in 样式的样式。

        // open document
        Object oFilePath = "C://Users/myDoc.docx";   
        Microsoft.Office.Interop.Word._Document myDoc;
        myDoc = wrdApp.Documents.Open(ref oFilePath, ref oMissing,
                            ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                            ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                            ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                            ref oMissing, ref oMissing
                       );
        // Change header2 style
        myDoc.Styles[WdBuiltinStyle.wdStyleHeading2].Font.Color = WdColor.wdColorOrange;


        //save and close doc
        myDoc.Save();
        Object oFalse = false;
        myDoc.Close(ref oFalse, ref oMissing, ref oMissing);

代码成功改变了标题文字的颜色,但文字前的数字仍然保持绿色,不受代码影响。像下图一样。

请给我一些提示,让我也将颜色更改应用于 heading.Thank 你的编号。

是的,您可以使用 API

//To Cancel the numerotation
ListTemplate lt = null;
myDoc.Styles[WdBuiltinStyle.wdStyleHeading2].LinkToListTemplate(lt);

//To add First Level of Numerotation
ListGallery gallery = wrdApp.ListGalleries[WdListGalleryType.wdNumberGallery];
myDoc.Styles[WdBuiltinStyle.wdStyleHeading2].LinkToListTemplate(gallery.ListTemplates[1]);