Skip to main content
 首页 » 编程设计

c#之如何以编程方式向 C# Excel vsto 中的单元格添加彩色边框

2024年02月20日10小虾米

如何在 C# Excel VSTO 中为单元格添加彩色边框?

我通过下面的链接找到了API,里面有一些关于添加边框的说明,但不是很具体。奇怪的是 VS2010 不识别 BorderAround() 方法。它似乎只识别BorderAround2(),但提示我输入的参数。

下面是我试过的代码,但是 VS 提示参数无效。

range.BorderAround2(Excel.XlLineStyle.xlDash, Type.Missing, Type.Missing, System.Drawing.Color.Red, Type.Missing); 

http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.range.borderaround(v=office.14).aspx

请您参考如下方法:

我自己的方法类似于 idssl 建议的方法,但利用了 ColorTranslator.ToOle方法。

range.Borders.LineStyle = Excel.XlLineStyle.xlDot; 
range.Borders.Color = ColorTranslator.ToOle(Color.Red); 

这也适用于我。