c# – 在Word中更改文本backgroundcolor

c# – 在Word中更改文本backgroundcolor,第1张

概述情况: > .net 3.5 > c#或vb.net(也经过测试) > word 2007加载项 我正在尝试将文本的背景颜色设置为自定义rgb颜色. 代码如下: Range r = this.Application.ActiveDocument.Range();r.Text = "blabla";r.Font.Shading.BackgroundPatternColor =(WdColor) 情况:

> .net 3.5
> c#或vb.net(也经过测试)
> word 2007加载项

我正在尝试将文本的背景颜色设置为自定义rgb颜色.

代码如下:

Range r = this.Application.Activedocument.Range();r.Text = "blabla";r.Font.Shading.BackgroundPatterncolor =(Wdcolor) color.FromArgb(0,214,227,188).ToArgb();

起初它似乎有效,除了颜色不正确.似乎每当我设置自定义颜色时,它都会将其更改为现有的Wdcolor常量.看看doc,它说:

Returns or sets the 24-bit color that’s applIEd to the background of the Shading object. Can be any valID Wdcolor constant or a value returned by Visual Basic’s RGB function.

所以,我的问题是:是否有人知道它应该如何运作?

感谢名单

解决方法 使用 ColorTranslator
Range r = this.Application.Activedocument.Range();r.Text = "blabla";r.Font.Shading.BackgroundPatterncolor =(Wdcolor)colorTranslator.Toole(0,188);
总结

以上是内存溢出为你收集整理的c# – 在Word中更改文本backgroundcolor全部内容,希望文章能够帮你解决c# – 在Word中更改文本backgroundcolor所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1262172.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存