Show and Hide Worksheets and Tabs
Show and Hide a Worksheet
An Excel file can have one or more than one worksheets. Whenever we create an Excel file, we add worksheets to the Excel file in which we work. Each worksheet in an Excel file is independent from the other worksheet by having its own data and formatting settings etc. Sometimes, developers may require to make few worksheets hidden and others visible in the Excel file for their own interest. So, Aspose.Cells allows developers to control the visibility of the worksheets in their Excel files.
Aspose.Cells provides a class, Workbook, that represents an 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 to manage worksheets. To control a worksheet’s visibility, use the IsVisible property of the Worksheet class. IsVisible is a Boolean property, which means that it can only store a true or false value.
Making a Worksheet Visible
Make a worksheet visible by setting the Worksheet class' IsVisible property to true
Hiding a Worksheet
Hide a worksheet by setting the Worksheet class' IsVisible property to false.
Show and Hide Tabs
If you closely look at the bottom of a Microsoft Excel file, you will see a number of controls. These include:
- Sheet tabs.
- Tab scrolling buttons.
Sheet tabs represent the worksheets in the Excel file. Click any tab to switch to that worksheet. The more worksheets in the workbook, the more sheet tabs there are. If the Excel file has a good number of worksheets you need buttons to navigate through them. So, Microsoft Excel provides tab scrolling buttons for scrolling through the sheet tabs.
Using Aspose.Cells, developers can control the visibility of sheet tabs and tabs scrolling buttons in Excel files.
Aspose.Cells provides a class, Workbook, that represents an Excel file. The Workbook class provides a wide range of properties and methods to manage an Excel file. To control the visibility of tabs in an Excel file, developers can use the Workbook class' WorkbookSettings.ShowTabs property. WorkbookSettings.ShowTabs is a Boolean property, which means that it can only store a true or false value.
Making Tabs Visible
Make tabs visible with the Workbook class' WorkbookSettings.ShowTabs property to true.
Hiding Tabs
Hide tabs in an Excel file by setting the Workbook class' WorkbookSettings.ShowTabs property to false.
Below is a complete example that opens an Excel file (book1.xls), hides its tabs and saves the modified file as output.xls. After the code execution, you will see that the tabs of the workbook are hidden.
Controlling the Tab Bar Width