Skip to main content

Use the Excel Export API to Hide a Worksheet

  • 2 minutes to read

The example below demonstrates how to manage worksheet visibility in a workbook. To do this, use the IXlSheet.VisibleState property.

Set this property to the XlSheetVisibleState.Hidden value to hide a worksheet. End-users can show a hidden worksheet from the user interface (for example, when opening a workbook in Microsoft® Excel®). If you wish to prevent end-users from displaying hidden worksheets, mark a worksheet as “very hidden” by setting the IXlSheet.VisibleState property to XlSheetVisibleState.VeryHidden.

To restore the worksheet visibility, set the IXlSheet.VisibleState property to the XlSheetVisibleState.Visible enumeration member.

Important

A workbook must always contain at least one visible worksheet.

View Example

// Create the first worksheet. 
using (IXlSheet sheet = document.CreateSheet()) {
    sheet.Name = "Sales report";
}

// Create the second worksheet and specify its visibility.
using (IXlSheet sheet = document.CreateSheet()) {
    sheet.Name = "Sales data";
    sheet.VisibleState = XlSheetVisibleState.Hidden;
}

The image below shows the result. The “Sales data” worksheet is hidden, but its visibility can be restored by an end-user from the user interface (the document is opened in Microsoft® Excel®).

XLExport_Examples_HideSheet