简体   繁体   English

Excel单元格中的VSTO对角线

[英]VSTO diagonal line in an Excel cell

I am currently trying to find a way using VSTO in C# for Excel, to draw a diagonal line in a cell using C# code. 我目前正试图在C#for Excel中找到一种使用VSTO的方法,使用C#代码在单元格中绘制对角线。 But i can't find anyone on the web who even tried to do this. 但我找不到任何人在网上甚至试图这样做。

Does anyone know how to achieve this ? 有谁知道如何实现这一目标?

Thank you 谢谢

(Excuse me for my bad english but it's not my language) (请原谅我的英语不好,但这不是我的语言)

You can manipulate borders as follows: 您可以按如下方式操纵边框:

Excel.Range range = ... the cell(s) you want ...;

var border = range.Borders[Excel.XlBordersIndex.xlDiagonalDown];
border.Weight = Excel.XlBorderWeight.xlThin;
border.LineStyle = Excel.XlLineStyle.xlContinuous;

The XlBordersIndex enumeration specifies which border you want to update: XlBordersIndex枚举指定要更新的边框:

xlDiagonalDown
xlDiagonalUp
xlEdgeBottom
xlEdgeLeft
xlEdgeRight
xlEdgeTop
...

I do not how in VSTO, but using COM you can do something like this: 我不知道如何在VSTO,但使用COM你可以做这样的事情:

ActiveSheet.Shapes.AddLine(BeginX, BeginY, EndX, EndY); ActiveSheet.Shapes.AddLine(BeginX,BeginY,EndX,EndY);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM