How to hide or show gridlines on a worksheet in C#

Gridlines are the faint lines used to distinguish cells on the excel worksheet. It helps readers to view and check the data easily on a worksheet. All Excel worksheets have gridlines by default and when we print the excel files, the gridlines won't be printed. So we may need to hide the gridlines to have exact preview for the print result. With the help of Spire.XLS, developers can easily hide or show the gridlines on Excel worksheet. This article will show you how to display or hide the gridlines on a worksheet in C#. Here comes to the steps:

Step 1: Create a new document and load from file.

Workbook workbook = new Workbook();
workbook.LoadFromFile("sample.xlsx");

Step 2: Get the worksheets in the excel workbook.

Worksheet worksheet = workbook.Worksheets[0];
Worksheet worksheet1 = workbook.Worksheets[1];

Step 3: Hide or show the gridlines by setting the property of GridLinesVisible.

//Hiding the gridlines for the first worksheet
worksheet.GridLinesVisible = false;
//Show the gridlines for the second worksheet
worksheet1.GridLinesVisible = true;

Step 4: Save the document to file.

workbook.SaveToFile("result.xlsx", ExcelVersion.Version2010);

Effective screenshot of hide the gridlines on excel worksheet:

How to hide or show gridlines on a worksheet in C#

The screenshot of show the gridlines on excel worksheet:

How to hide or show gridlines on a worksheet in C#

Full codes:

static void Main(string[] args)
{
    Workbook workbook = new Workbook();
    workbook.LoadFromFile("sample.xlsx");

    Worksheet worksheet = workbook.Worksheets[0];
    Worksheet worksheet1 = workbook.Worksheets[1];
    
    worksheet.GridLinesVisible = false;
    worksheet1.GridLinesVisible = true;
    workbook.SaveToFile("result.xlsx", ExcelVersion.Version2010);
}