officefileapi-114081-excel-export-library-rows-and-columns-how-to-specify-row-height-and-column-width.md
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;
}
}
' Create a new worksheet.
Using sheet As IXlSheet = document.CreateSheet()
' Create the column A and set its width to 100 pixels.
Using column As IXlColumn = sheet.CreateColumn()
column.WidthInPixels = 100
End Using
' Create the column B and set its width to 24.5 characters.
Using column As IXlColumn = sheet.CreateColumn()
column.WidthInCharacters = 24.5f
End Using
End Using
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;
}
}
' Create a new worksheet.
Using sheet As IXlSheet = document.CreateSheet()
' Create the third row and set its height to 40 pixels.
Using row As IXlRow = sheet.CreateRow(2)
row.HeightInPixels = 40
End Using
End Using
See Also