c# - 使用编号自定义 Microsoft Word 内置样式
问题描述
我有一个 word 文档,它已经定义了装扮的内置样式。如下图。
我想通过运行下面的 C# 代码来更改预定义的内置样式的样式。
// 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);
代码成功更改了标题文本的颜色,但文本前面的数字仍然保持绿色,不受代码影响。就像下图一样。
请给我一些提示,以将颜色更改应用于标题编号。谢谢。
解决方案
是的,您可以使用 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]);
推荐阅读
- python - 从csv文件读取时如何将多个值保存到列表中?
- android - 手机进入睡眠状态时Android应用程序停止进程
- php - phpMyAdmin 502 网关错误 [CentOS7, nginx]
- r - 重新安装后 RStudio 不再工作
- amazon-web-services - 在 jenkins 参数的下拉列表中动态填充分支
- arrays - 从数组中打印字符串
- javascript - 猫头鹰旋转木马不工作!初级网络开发人员
- jquery - 如何将 jquery-ui 与 nodejs 一起使用?
- python - 用 pandas 读取 xml 文件
- python - Django 搞乱了加载标签的顺序?