Skip to main content

Use the Excel Export API to Specify Row Height and Column Width

  • 2 minutes to read

Columns

To specify a column width in characters of the default font defined by the Normal style, use the column’s IXlColumn.WidthInCharacters property.

To specify a column width in pixels, use the column’s IXlColumn.WidthInPixels property.

Note

If a column width is set to 0, the column is hidden. You can also use the IXlColumn.IsHidden property to hide a column or display the hidden column again (see the How to: Hide a Row or Column document).

View Example: Excel Export API

// Create a new worksheet.
using (IXlSheet sheet = document.CreateSheet()) 
{
    // Create the column A and set its width to 100 pixels.
    using (IXlColumn column = sheet.CreateColumn())
    {
        column.WidthInPixels = 100;
    }

    // Create the column B and set its width to 24.5 characters.
    using (IXlColumn column = sheet.CreateColumn())
    {
        column.WidthInCharacters = 24.5f;
    }
}

Rows

To specify a row height in pixels, use the row’s IXlRow.HeightInPixels property.

To specify a row height in points, use the row’s IXlRow.HeightInPoints property.

Note

If the row height is set to 0, the row is hidden. You can also use the IXlRow.IsHidden property to hide a row or display the hidden row again (see the How to: Hide a Row or Column document).

View Example: Excel Export API

// Create a new worksheet.
using (IXlSheet sheet = document.CreateSheet()) 
{
    // Create the third row and set its height to 40 pixels.
    using (IXlRow row = sheet.CreateRow(2))
    {
        row.HeightInPixels = 40;
    }
}
See Also