Matt Colon Matt Colon - 2 months ago 62
C# Question

EPPlus Changing Border Color of cells

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

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.