我正在尝试使用office.interop更改word文档样式的字体颜色,但颜色不会改变。任何想法?我以两种不同的方式尝试过。第一种是通过尝试更改ms字词中标题样式的颜色:这是一些代码:
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;
谢谢
编辑:
这是解决方案:
(document.Styles[WdBuiltinStyle.wdStyleHeading2]).Font.ColorIndex = WdColorIndex.wdBlack;
谢谢
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句