如何更改word文档样式中的字体颜色
how to change font color in a word document style
我正在尝试使用 office.interop 更改 word 文档样式的字体颜色,但颜色没有改变。任何的想法?
我尝试了两种不同的方式。
第一种是尝试更改 ms word 中标题样式的颜色:
这是一些代码:
Application appWord=new Application();
Document doc=new Document();
ListGallery gallery=appWord.ListGalleries[WdListGalleryType.wdNumberGallery];
ListTemplate template =gallery.ListTemplates[4];
Style style=doc.ListTemplate[2];
style.LinkToListTemplate(template,1);
style.Font.ColorIndex=WdColorIndex.WdBlack;//doesn't work
doc.saveAs2(path);
第二种方法是在将文件插入 ms doc 后尝试设置范围或选择的颜色:
Paragraph p3 = wordDocument.Paragraphs.Add();
Range r3 = p3.Range;
//r3.Font.TextColor = WdColor.wdColorBlack;
var filename=String.Format("{0}Resources/TEST1.html", AppDomain.CurrentDomain.BaseDirectory);
String newString=System.IO.File.ReadAllText(filename).Replace("</body>","<p>1</p></body>");
System.IO.File.WriteAllText(filename, newString);
appWord.Selection.Font.ColorIndex = WdColorIndex.wdBrightGreen;
r3.InsertFile(filename);
//r3.Font.olorIndex = WdColorIndex.wdBrightGreen;
编辑:
解决方法如下:
(document.Styles[WdBuiltinStyle.wdStyleHeading2]).Font.ColorIndex = WdColorIndex.wdBlack;
谢谢
你已经在你的程序中写好了
style.Font.ColorIndex=WdColorIndex=WdBlack;
//不起作用
将上面的行更正为
style.Font.ColorIndex=WdColorIndex.WdBlack; // this will work
编辑:
解决方法如下:
(document.Styles[WdBuiltinStyle.wdStyleHeading2]).Font.ColorIndex = WdColorIndex.wdBlack;
谢谢
我正在尝试使用 office.interop 更改 word 文档样式的字体颜色,但颜色没有改变。任何的想法? 我尝试了两种不同的方式。 第一种是尝试更改 ms word 中标题样式的颜色: 这是一些代码:
Application appWord=new Application();
Document doc=new Document();
ListGallery gallery=appWord.ListGalleries[WdListGalleryType.wdNumberGallery];
ListTemplate template =gallery.ListTemplates[4];
Style style=doc.ListTemplate[2];
style.LinkToListTemplate(template,1);
style.Font.ColorIndex=WdColorIndex.WdBlack;//doesn't work
doc.saveAs2(path);
第二种方法是在将文件插入 ms doc 后尝试设置范围或选择的颜色:
Paragraph p3 = wordDocument.Paragraphs.Add();
Range r3 = p3.Range;
//r3.Font.TextColor = WdColor.wdColorBlack;
var filename=String.Format("{0}Resources/TEST1.html", AppDomain.CurrentDomain.BaseDirectory);
String newString=System.IO.File.ReadAllText(filename).Replace("</body>","<p>1</p></body>");
System.IO.File.WriteAllText(filename, newString);
appWord.Selection.Font.ColorIndex = WdColorIndex.wdBrightGreen;
r3.InsertFile(filename);
//r3.Font.olorIndex = WdColorIndex.wdBrightGreen;
编辑:
解决方法如下:
(document.Styles[WdBuiltinStyle.wdStyleHeading2]).Font.ColorIndex = WdColorIndex.wdBlack;
谢谢
你已经在你的程序中写好了
style.Font.ColorIndex=WdColorIndex=WdBlack;
//不起作用
将上面的行更正为
style.Font.ColorIndex=WdColorIndex.WdBlack; // this will work
编辑:
解决方法如下:
(document.Styles[WdBuiltinStyle.wdStyleHeading2]).Font.ColorIndex = WdColorIndex.wdBlack;
谢谢