我试图使用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;谢谢
发布于 2016-09-14 13:09:10
编辑:
以下是解决办法:
(document.Styles[WdBuiltinStyle.wdStyleHeading2]).Font.ColorIndex = WdColorIndex.wdBlack;谢谢
发布于 2016-09-10 01:38:35
你已经在你的程序里写了
style.Font.ColorIndex=WdColorIndex=WdBlack;//不工作
将上述行更正为
style.Font.ColorIndex=WdColorIndex.WdBlack; // this will workhttps://stackoverflow.com/questions/39421615
复制相似问题