Back to Devexpress

How to: Specify Row Height or Column Width

windowsforms-15398-controls-and-libraries-spreadsheet-examples-rows-and-columns-how-to-specify-row-height-or-column-width.md

latest4.3 KB
Original Source

How to: Specify Row Height or Column Width

  • Dec 09, 2022
  • 5 minutes to read

Row

This example demonstrates how to control the row height on a worksheet.

  • Set Height for Individual Rows

  • AutoFit Row Height

  • Match the Height of Two Rows

  • Set the Default Row Height

  • Set the Height for All Rows on a Worksheet

View Example

csharp
// Set the height of the 3rd row to 50 points
workbook.Unit = DevExpress.Office.DocumentUnit.Point;
worksheet.Rows[2].Height = 50;

// Set the height of the row that contains the "C5" cell to 2 inches.
workbook.Unit = DevExpress.Office.DocumentUnit.Inch;
worksheet.Cells["C5"].RowHeight = 2;

// Set the height of the 7th row to the height of the 3rd row.
worksheet.Rows["7"].Height = worksheet.Rows["3"].Height;

// Set the default row height to 30 points.
workbook.Unit = DevExpress.Office.DocumentUnit.Point;
worksheet.DefaultRowHeight = 30;
vb
' Set the height of the 3rd row to 50 points
workbook.Unit = DevExpress.Office.DocumentUnit.Point
worksheet.Rows(2).Height = 50

' Set the height of the row that contains the "C5" cell to 2 inches.
workbook.Unit = DevExpress.Office.DocumentUnit.Inch
worksheet.Cells("C5").RowHeight = 2

' Set the height of the 7th row to the height of the 3rd row.
worksheet.Rows("7").Height = worksheet.Rows("3").Height

' Set the default row height to 30 points.
workbook.Unit = DevExpress.Office.DocumentUnit.Point
worksheet.DefaultRowHeight = 30

Column

This example demonstrates how to control the column width on a worksheet.

  • Set the Width for Individual Columns

  • AutoFit Column Width

  • Match the Width of Two Columns

  • Set the Default Column Width

  • Set the Width for All Columns on a Worksheet

View Example

csharp
// Set the "B" column width to 30 characters of the default font that is specified by the Normal style.
worksheet.Columns["B"].WidthInCharacters = 30;

// Set the "C" column width to 15 millimeters.
workbook.Unit = DevExpress.Office.DocumentUnit.Millimeter;
worksheet.Columns["C"].Width = 15;

// Set the width of the column that contains the "E15" cell to 100 points.
workbook.Unit = DevExpress.Office.DocumentUnit.Point;
worksheet.Cells["E15"].ColumnWidth = 100;

// Set the width of all columns that contain the "F4:H7" cell range (the "F", "G" and "H" columns) to 70 points.
worksheet.Range["F4:H7"].ColumnWidth = 70;

// Set the "J" column width to the "B" column width value.
worksheet.Columns["J"].Width = worksheet.Columns["B"].Width;

// Copy the "C" column width value and assign it to the "K" column width.
worksheet.Columns["K"].CopyFrom(worksheet.Columns["C"], PasteSpecial.ColumnWidths);

// Set the default column width to 40 pixels.
worksheet.DefaultColumnWidthInPixels = 40;
vb
' Set the "B" column width to 30 characters of the default font that is specified by the Normal style.
worksheet.Columns("B").WidthInCharacters = 30

' Set the "C" column width to 15 millimeters.
workbook.Unit = DevExpress.Office.DocumentUnit.Millimeter
worksheet.Columns("C").Width = 15

' Set the width of the column that contains the "E15" cell to 100 points.
workbook.Unit = DevExpress.Office.DocumentUnit.Point
worksheet.Cells("E15").ColumnWidth = 100

' Set the width of all columns that contain the "F4:H7" cell range (the "F", "G" and "H" columns) to 70 points.
worksheet.Range("F4:H7").ColumnWidth = 70

' Set the "J" column width to the "B" column width value.
worksheet.Columns("J").Width = worksheet.Columns("B").Width

' Copy the "C" column width value and assign it to the "K" column width.
worksheet.Columns("K").CopyFrom(worksheet.Columns("C"), PasteSpecial.ColumnWidths)

' Set the default column width to 40 pixels.
worksheet.DefaultColumnWidthInPixels = 40

See Also

Rows and Columns in Spreadsheet Documents