0

I created an Excel sheet, using ExcelPackage. I gave some cells a different color, for clearing up the sheet.

Problem:

The default grid gets removed as in picture below: Custom colored fields

First Column has the default grid overlay, the other ones don't have this grid. I tried re-enabling that grid and tried using the following code:

worksheet.Cells[row, col].Style.Border.BorderAround(ExcelBorderStyle.None);

Above code gave me same as picture.

worksheet.Cells[row, col].Style.Border.BorderAround(ExcelBorderStyle.Thin);

Above code gave me a thicker line than the default.

worksheet.Cells[row, col].Style.Border.BorderAround(ExcelBorderStyle.Medium);

Above code gave me a even thicker line than the default.

worksheet.Cells[row, col].Style.Border.BorderAround(ExcelBorderStyle.Hair);

Above code gave me a dotted line.

Question:

Can someone help me with this, where can I find the correct syntax, since the community on ExcelPackage isn't that big and I can't find it on their CodePlex page.

Max
  • 12,622
  • 16
  • 73
  • 101

1 Answers1

1

Because you are setting Fill colours within the cells the default grid is removed, this functionality can also be seen within Excel by simply setting a background color of a cell. So you will have to manually add the borders to display them.

This will mean you will most likely have to come up with a new border style for the entire grid. Example :

worksheet.Cells[row, col].Style.Border.Bottom.BorderAround(ExcelBorderStyle.Thin);
worksheet.Cells[row, col].Style.Border.Bottom.Color.SetColor(System.Drawing.Color.Black);

Alternatively if you have a need to remove cell backgrounds you can do the following :

worksheet.Cells[row, col].Style.Border.Bottom.BorderAround(ExcelBorderStyle.None);
worksheet.Cells[row, col].Style.Fill.PatternType = ExcelFillStyle.None;

This will set the default background and border styles for the cell.

Hope this helps.

Nunners
  • 3,047
  • 13
  • 17