C# – Hide and Unhide a Worksheet

As is known, one workbook presents three worksheets by default. Sometimes, people need to hide one worksheet because it has stored some useful data. When they want to use or print data in hidden worksheet, just unhide.

In this post, I will show the method to hide and unhide worksheet in a workbook. In my example, I have prepared a sale report file. There are three worksheets in it but just the first one stores data. I will hide this sheet firstly and then unhide it.

Sales Report

Spire.XLS is used in this method, so I add its DLL file as reference in my project.


1. Load file which I want to hide worksheet

            Workbook workbook = new Workbook();

            workbook.LoadFromFile(@"D:\work\My Documents\Sales Report.xlsx");

2. Hide the first worksheet.

            Worksheet worksheet = workbook.Worksheets[0];

            worksheet.Visibility = WorksheetVisibility.Hidden;

                If you want to hide worksheet 2 or 3, change workbook.Worksheets[0] to 1 or 2.

3. Save and launch file.

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


Hide Result:


1. Load the file which I have hidden the first worksheet. This file is generated from the above hide program.


            Worksheet worksheet = workbook.Worksheets[0];

2. Unhide this hidden worksheet.

            worksheet.Visibility = WorksheetVisibility.Visible;

3. Save and launch new Excel file.



Unhide Result:


Click Here to learn more about Spire.XLS

Click Here to Download Spire.XLS


3 thoughts on “C# – Hide and Unhide a Worksheet

  1. Filmy says:

    I have seen that currently, more and more people are increasingly being attracted to video cameras and the issue of photography. However, as a photographer, you will need to first invest so much time frame deciding the model of digicam to buy along with moving via store to store just so you could possibly buy the cheapest camera of the trademark you have decided to select. But it will not end generally there. You also have to take into account whether you should purchase a digital photographic camera extended warranty. Thanks for the good recommendations I received from your web site.

  2. Daryl Nabozny says:

    Hi there! This post couldn’t be written any better! Reading through this post reminds me of my previous room mate! He always kept talking about this. I will forward this article to him. Pretty sure he will have a good read. Thank you for sharing!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s