Excel Range.BorderAround(),边框始终为黑色
这是我正在使用的代码:
rngData.BorderAround(Excel.XlLineStyle.xlContinuous,
Microsoft.Office.Interop.Excel.XlBorderWeight.xlThin,
Microsoft.Office.Interop.Excel.XlColorIndex.xlColorIndexNone,
System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.FromArgb(178, 178, 178)));
无论我提供什么 RGB 值,边框颜色始终为黑色。
This is the code I am using:
rngData.BorderAround(Excel.XlLineStyle.xlContinuous,
Microsoft.Office.Interop.Excel.XlBorderWeight.xlThin,
Microsoft.Office.Interop.Excel.XlColorIndex.xlColorIndexNone,
System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.FromArgb(178, 178, 178)));
The border color is always black no matter what RGB value I provide.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我遇到了同样的问题,在网上找不到任何解决方案,在 VSTO 中使用此方法的 MS 文档有点差。
不管怎样,对于你几个月前发布的内容来说可能有点晚了,但我的解决方法就是不使用 Range.BorderAround 方法并编写我自己的方法!
可以按照下面的示例调用(Contents_Table 是我工作表中的 NamedRange):
希望这可以帮助其他人撕扯他们的头发。
I had the same problem, couldn't find any solution on the web, MS documentation for use of this method in VSTO is a bit poor.
Anyway, probably a bit late for you seeing as you posted months ago, but my workaround was simply to not use the Range.BorderAround method and write my own!
Can be invoked as per below example (Contents_Table is a NamedRange in my worksheet):
Hope this helps someone else out there tearing their hair out.
或者,如果您不担心确保删除内部和对角线,我已成功使用:
Alternatively if you're not worried to ensure the removal of inside and diagonal lines I have successfully used:
要更改边框颜色,您必须使用
Color:=RGB(255, 0, 0)
以及您感兴趣的 RGB 代码,或者
ColorIndex:=3
- 例如,获取红色。如果同时使用,
[ColorIndex:=3]
将覆盖[Color:=RGB(255, 0, 0)]
- 当您尝试设置不同颜色时操作可见对于每个,或使用[colorindex:=xlColorIndeAutomatic]
或使用[xlColorIndexNone]
。与 Excel 公式不同,在 VBA 中,您可以而且可能应该跳过 VBA 智能感知建议的参数...
To change the border color you have to use either
Color:=RGB(255, 0, 0)
with the RGB code you're interesting in, or
ColorIndex:=3
- to get the red color, for instance.If you use both,
[ColorIndex:=3]
will override[Color:=RGB(255, 0, 0)]
- action visible when you try to set different colors for each, or use[colorindex:=xlColorIndeAutomatic]
or with[xlColorIndexNone]
.Unlike in Excel formulas, in VBA you can and probably should skip parameters as they are suggested by VBA's intellisense...