Show and Hide Worksheets and Tabs

Show and Hide a Worksheet

An Excel file can have one or more 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 of the other worksheets, having its own data and formatting settings, etc. Sometimes, developers may require to make a few worksheets hidden and others visible in the Excel file as needed. 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’s IsVisible property to true.

Hiding a Worksheet

Hide a worksheet by setting the Worksheet class’s 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 large number of worksheets, you need buttons to navigate through them. Microsoft Excel provides tab scrolling buttons for scrolling through the sheet tabs.

Using Aspose.Cells, developers can control the visibility of sheet tabs and tab 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’s 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 by setting the Workbook class’s WorkbookSettings.ShowTabs property to true.

Hiding Tabs

Hide tabs in an Excel file by setting the Workbook class’s 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