Donate

How To Add Cell Borders Or Grid Lines To Filled Cells In Excel Using ClosedXML

Hello,

When dealing with filled cells or columns of an Excel workshet via ClosedXML, you may notice that after you produced the Excel file(s), the filled columns or cells don't have borders. This assume that your report does not apply borders to the used cells or columns such as the image below.
How To Add Cell Borders Or Grid Lines To Filled Cells In Excel Using ClosedXML
To apply borders to certain columns within a range or not, you need to set both the Outside and Inside borders with Thin borderstyle. And then apply your preferred color to the top, bottom, left and right borders.
row++;
xlWSheet.Range(1, 1, row, 7).Style.Border.SetOutsideBorder(XLBorderStyleValues.Thin)
.Border.SetInsideBorder(XLBorderStyleValues.Thin)
.Border.SetTopBorderColor(XLColor.LightGray)
.Border.SetBottomBorderColor(XLColor.LightGray)
.Border.SetLeftBorderColor(XLColor.LightGray)
.Border.SetRightBorderColor(XLColor.LightGray);
Filled columns or cells with borders.
How To Add Cell Borders Or Grid Lines To Filled Cells In Excel Using ClosedXML


Cheers!

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.