How to change the grid line color of the Excel sheet?

29 Nov 20242 minutes to read

In Essential® XlsIO, you can change the grid line color of the worksheet using GridLineColor property. The below code snippet illustrate this.

using (ExcelEngine excelEngine = new ExcelEngine())
{
  IApplication application = excelEngine.Excel;
  application.DefaultVersion = ExcelVersion.Excel2013;
  IWorkbook workbook = application.Workbooks.Create(1);
  IWorksheet worksheet = workbook.Worksheets[0];

  //To change the grid line color using ExcelKnownColors
  worksheet.GridLineColor = ExcelKnownColors.Blue;

  FileStream stream = new FileStream("GridLineColor.xlsx", FileMode.OpenOrCreate, FileAccess.ReadWrite);
  workbook.SaveAs(stream);
  workbook.Close();
  excelEngine.Dispose();
}
using (ExcelEngine excelEngine = new ExcelEngine())
{
  IApplication application = excelEngine.Excel;
  application.DefaultVersion = ExcelVersion.Excel2013;
  IWorkbook workbook = application.Workbooks.Create(1);
  IWorksheet worksheet = workbook.Worksheets[0];

  //To change the grid line color using ExcelKnownColors
  worksheet.GridLineColor = ExcelKnownColors.Blue;

  workbook.SaveAs("GridLineColor.xlsx");
}
Using excelEngine As ExcelEngine = New ExcelEngine()
  Dim application As IApplication = excelEngine.Excel
  application.DefaultVersion = ExcelVersion.Excel2013
  Dim workbook As IWorkbook = application.Workbooks.Create(1)
  Dim worksheet As IWorksheet = workbook.Worksheets(0)

  'To change the grid line color using ExcelKnownColors
  worksheet.GridLineColor = ExcelKnownColors.Blue

  workbook.SaveAs("GridLineColor.xlsx")
End Using

See Also