Introduction
All worksheets in an Excel file are composed of cells that are arranged in the form of rows and columns. All rows and columns have unique values that are used to identify a particular row, column or cell. For example, rows are numbered as 1, 2, 3, 4 etc. and columns are ordered alphabetically as A, B, C, D etc. These values of the rows and columns are displayed as their headers. Rows and columns, both have their own row and column headers respectively. Using, Aspose.Cells , developers can control the visibility of these row/column headers in their worksheets.
Controlling the Visibility of the Worksheets
Aspose.Cells provides a class, Workbook that represents an Excel file. Workbook class contains a Worksheets collection that allows to access each worksheet in the Excel file.
A worksheet is represented by the Worksheet class. Worksheet class provides a wide range of properties and methods to manage a worksheet. But, to control the visibility of row/column headers, developers may use IsRowColumnHeadersVisible property of the Worksheet class. IsRowColumnHeadersVisible is a boolean property, which means that it can only store a true or false value.
Hiding Row/Column Headers
Developers can hide row/column headers by setting the IsRowColumnHeadersVisible property of the Worksheet class to false.
Example:
[C#]
//Hiding the headers of rows and columns
worksheet.IsRowColumnHeadersVisible = false;
[VB.NET]
'Hiding the headers of rows and columns
worksheet.IsRowColumnHeadersVisible = False
[JAVA]
//Hiding the headers of rows and columns
worksheet.setRowColumnHeadersVisible(false);
Making Row/Column Headers Visible
Developers can make row/column headers visible by setting the IsRowColumnHeadersVisible property of the Worksheet class to true.
Example:
[C#]
//Displaying the headers of rows and columns
worksheet.IsRowColumnHeadersVisible = true;
[VB.NET]
'Displaying the headers of rows and columns
worksheet.IsRowColumnHeadersVisible = True
[JAVA]
//Displaying the headers of rows and columns
worksheet.setRowColumnHeadersVisible(true);
Example:
A complete example is given below that demonstrates the use of IsRowColumnHeadersVisible property of Worksheet class to hide the row/column headers of the first worksheet of the Excel file.
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream("C:\\book1.xls",FileMode.Open);
//Opening the Excel file through the file stream
workbook.Open(fstream);
//Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];
//Hiding the headers of rows and columns
worksheet.IsRowColumnHeadersVisible = false;
//Saving the modified Excel file in default (that is Excel 2000) format
workbook.Save("C:\\output.xls",FileFormatType.Default);
//Closing the file stream to free all resources
fstream.Close();
[VB.NET]
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Creating a file stream containing the Excel file to be opened
Dim fstream As FileStream = New FileStream("C:\\book1.xls",FileMode.Open)
'Opening the Excel file through the file stream
workbook.Open(fstream)
'Accessing the first worksheet in the Excel file
Dim worksheet As Worksheet = workbook.Worksheets(0)
'Hiding the headers of rows and columns
worksheet.IsRowColumnHeadersVisible=False
'Saving the modified Excel file in default (that is Excel 2000) format
workbook.Save("C:\\output.xls",FileFormatType.Default)
'Closing the file stream to free all resources
fstream.Close()
[JAVA]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Opening the Excel file
workbook.open("C:\\book1.xls");
//Accessing the first worksheet in the Excel file
Worksheets worksheets = workbook.getWorksheets();
Worksheet worksheet = worksheets.getSheet(0);
//Hiding the headers of rows and columns
worksheet.setRowColumnHeadersVisible(false);
//Saving the modified Excel file in default (that is Excel 2000) format
workbook.save("C:\\output.xls");
Worksheet - Before Modification
In the screenshot below, you can see that Book1.xls file contains three worksheets: Sheet1, Sheet2 and Sheet3. Each worksheet has its row/column headers visible as shown below:
|
Figure: Worksheet view before any modification
|
Worksheet - After Executing the Example Code
Book1.xls file is opened by calling the Open method of Workbook class and then the row/column headers of the first worksheet of the Book1.xls file are made hidden. The modified file is saved as output.xls file whose pictorial view is shown below:
|
Figure: Worksheet view after modification
|