Home » excel » c# – VSTO diagonal line in an Excel cell

c# – VSTO diagonal line in an Excel cell

Posted by: admin May 14, 2020 Leave a comment

Questions:

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

How to&Answers:

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:

xlDiagonalDown
xlDiagonalUp
xlEdgeBottom
xlEdgeLeft
xlEdgeRight
xlEdgeTop
...

Answer:

I do not how in VSTO, but using COM you can do something like this:

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