Back to Devexpress

Row.Height Property

officefileapi-devexpress-dot-spreadsheet-dot-row-b2f89281.md

latest9.7 KB
Original Source

Row.Height Property

Gets or sets the row height.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
double Height { get; set; }
vb
Property Height As Double

Property Value

TypeDescription
Double

The row height in measurement units defined by the Workbook.Unit property.

|

Exceptions

TypeDescription
ArgumentException

Occurs if the row height exceeds 409 points.

|

Example

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

Set Height for Individual Rows

Use the Row.Height or CellRange.RowHeight property to set the row height in the workbook’s measurement units.

Note

If the row height is set to 0, the row is hidden. You can also use the Row.Visible property to hide a row or display the hidden row again.

AutoFit Row Height

To automatically change the row height to fit the contents, use the row’s Row.AutoFit method. To quickly autofit several rows in a worksheet, use the RowCollection.AutoFit method.

Use the SpreadsheetCellOptions.AutoFitMergedCellRowHeight property to enable the AutoFit functionality for rows that have cells merged across.

Match the Height of Two Rows

To match one row height to another, make their Row.Height property values equal.

Set the Default Row Height

To set the default height for worksheet rows, use the Worksheet.DefaultRowHeight property. This property does not affect rows with an explicitly specified height.

Set the Height for All Rows in a Worksheet

To change the height of all rows in a worksheet, use the CellRange.RowHeight property of the Column object corresponding to any column in a worksheet. This sets the height of all rows to the same value, overriding all previously applied row height settings.

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

The following code snippets (auto-collected from DevExpress Examples) contain references to the Height property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

spreadsheet-document-api-examples-part1/CS/SpreadsheetExamples/SpreadsheetActions/RowAndColumnActions.cs#L101

csharp
worksheet.Cells["A2"].Value = "Row 2";
worksheet.Rows["2"].Height = 150;
worksheet.Rows["2"].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;

winforms-spreadsheet-use-custom-cell-editors/CS/DevAVInvoicing/Form1.cs#L185

csharp
sheet.Rows.Insert(rowIndex);
sheet.Rows[rowIndex].Height = sheet.Rows[rowIndex + 1].Height;
CellRange range = invoiceItems.Range;

winforms-spreadsheetcontrol-api-part1/CS/SpreadsheetControl/SpreadsheetActions/RowAndColumnActions.cs#L111

csharp
worksheet.Cells["A2"].Value = "Row 2";
worksheet.Rows["2"].Height = 50;
worksheet.Rows["2"].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;

winforms-spreadsheetcontrol-api-part-2/CS/SpreadsheetControl_API_Part02/SpreadsheetActions/PictureActions.cs#L105

csharp
pic.Placement = Placement.MoveAndSize;
worksheet.Rows[1].Height += 20;
worksheet.Columns["D"].Width += 20;

wpf-spreadsheetcontrol-api-part-2/CS/SpreadsheetControl_WPF_API_Part02/SpreadsheetActions/ShapeActions.cs#L98

csharp
pic.Placement = Placement.MoveAndSize;
worksheet.Rows[5].Height += 10;
worksheet.Columns["D"].Width += 10;

spreadsheet-document-api-examples-part1/VB/SpreadsheetExamples/SpreadsheetActions/RowAndColumnActions.vb#L82

vb
worksheet.Cells("A2").Value = "Row 2"
worksheet.Rows("2").Height = 150
worksheet.Rows("2").Alignment.Vertical = SpreadsheetVerticalAlignment.Center

winforms-spreadsheet-use-custom-cell-editors/VB/DevAVInvoicing/Form1.vb#L172

vb
sheet.Rows.Insert(rowIndex)
sheet.Rows(rowIndex).Height = sheet.Rows(rowIndex + 1).Height
Dim range As CellRange = invoiceItems.Range

winforms-spreadsheetcontrol-api-part1/VB/SpreadsheetControl/SpreadsheetActions/RowAndColumnActions.vb#L113

vb
worksheet.Cells("A2").Value = "Row 2"
worksheet.Rows("2").Height = 50
worksheet.Rows("2").Alignment.Vertical = SpreadsheetVerticalAlignment.Center

winforms-spreadsheetcontrol-api-part-2/VB/SpreadsheetControl_API_Part02/SpreadsheetActions/PictureActions.vb#L98

vb
pic.Placement = Placement.MoveAndSize
worksheet.Rows(1).Height += 20
worksheet.Columns("D").Width += 20

wpf-spreadsheetcontrol-api-part-2/VB/SpreadsheetControl_WPF_API_Part02/SpreadsheetActions/ShapeActions.vb#L92

vb
pic.Placement = Placement.MoveAndSize
worksheet.Rows(5).Height += 10
worksheet.Columns("D").Width += 10

See Also

RowHeight

DefaultRowHeight

ColumnWidth

ColumnWidthInCharacters

Row Interface

Row Members

DevExpress.Spreadsheet Namespace