Skip to main content
A newer version of this page is available. .

How 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.

Note

A complete sample project is available at https://github.com/DevExpress-Examples/xl-export-api-examples-t253492

// 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