Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EPPlus Changing Border Color of cells

Tags:

c#

excel

epplus

I'm trying to change the cell border color on a selected range. Couldn't find any other styles for cell borders other than for the weights of the borders as follows:

range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
like image 682
Matteo Avatar asked Sep 13 '16 13:09

Matteo


2 Answers

you can change the border style and color using this code

range.Style.Border.BorderAround(ExcelBorderStyle.Medium, System.Drawing.Color.Blue);
like image 73
j.kahil Avatar answered Sep 18 '22 11:09

j.kahil


If you want to sent border colors on different parts of the cells you can do it like this:

range.Style.Border.Top.Color.SetColor(Color.Red);
range.Style.Border.Bottom.Color.SetColor(Color.Green);
range.Style.Border.Left.Color.SetColor(Color.Blue);
range.Style.Border.Right.Color.SetColor(Color.Yellow);

SetColor can take any kind of System.Drawing.Color.

like image 20
Ernie S Avatar answered Sep 19 '22 11:09

Ernie S