加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 在Word中更改文本backgroundcolor

发布时间:2020-12-15 04:08:45 所属栏目:百科 来源:网络整理
导读:情况: .net 3.5 c#或vb.net(也经过测试) word 2007加载项 我正在尝试将文本的背景颜色设置为自定义rgb颜色. 代码如下: Range r = this.Application.ActiveDocument.Range();r.Text = "blabla";r.Font.Shading.BackgroundPatternColor =(WdColor) Color.Fro
情况:

> .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);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读