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 IXl
// 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 IXl
// 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;
}
}