Display or Hide Gridlines in Aspose.Cells

Controlling the Visibility of the Gridlines

Aspose.Cells provides a class, Workbook, that represents a Microsoft Excel file. The Workbook class contains a Worksheets collection that allows access to each worksheet in the Excel file.

A worksheet is represented by the Worksheet class. The Worksheet class provides a wide range of properties and methods for managing a worksheet. To control the visibility of gridlines, use the Worksheet class' IsGridlinesVisible property. IsGridlinesVisible is a Boolean property, which means that it can only store a true or false value.

A complete example is given below that demonstrates the use of the IsGridlinesVisible property of the Worksheet class to hide the gridlines of the first worksheet of the Excel file.

In the screenshot below, you can see that the Book1.xls file contains three worksheets: Sheet1, Sheet2 and Sheet3. All worksheets have gridlines.

Book1.xls: worksheet view before modification


The Book1.xls file is opened by using the Workbook class and the gridlines on the first worksheet are hidden. The modified file is saved as output.xls.

Output.xls: worksheet after modification



 //Creating a file stream containing the Excel file to be opened

FileStream fstream = new FileStream("book1.xls", FileMode.Open);

//Instantiating a Workbook object

//Opening the Excel file through the file stream

Workbook workbook = new Workbook(fstream);

//Accessing the first worksheet in the Excel file

Worksheet worksheet = workbook.Worksheets[0];

//Hiding the gridlines of the first worksheet of the Excel file

worksheet.IsGridlinesVisible = false;

//Saving the modified Excel file


//Closing the file stream to free all resources


Download Running Code

Download Sample Code