EPPlus Changing Border Color of cells

Matteo picture Matteo · Sep 13, 2016 · Viewed 12.6k times · Source

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;

Answer

Ernie S picture Ernie S · Sep 13, 2016

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.