Use the Excel Export API to Hide a Row or Column

The example below demonstrates how to control the visibility of rows and columns in a worksheet using the IXlRow.IsHidden and IXlColumn.IsHidden properties.

Note

You can also hide a row or column in a worksheet by setting the row height (IXlRow.HeightInPixels) or column width (IXlColumn.WidthInCharacters or IXlColumn.WidthInPixels) to 0, respectively (see the How to: Specify Row Height and Column Width document).

// Create a new worksheet.
using (IXlSheet sheet = document.CreateSheet()) 
{
    // Hide the column B in the worksheet.
    using (IXlColumn column = sheet.CreateColumn(1))
    {
        column.IsHidden = true;
    }

    // Hide the third row in the worksheet.
    using (IXlRow row = sheet.CreateRow(2))
    {
        row.IsHidden = true;
    }
}
See Also