Class RangeRow
A class that represents a single row of cells.
Inherited Members
Namespace: IronXL
Assembly: IronXL.dll
Syntax
public class RangeRow : Range
RangeRow is the row-shaped view of an Excel sheet a developer holds in C# to size, hide, identify, or remove a single row as a unit. It is what a worksheet returns for one row, carrying the row-level operations that a plain block of cells does not, so code reaching for "C# Excel row" lands here.
Get a row from a worksheet with GetRow, passing the row index, which returns the RangeRow for that position. Because RangeRow derives from Range, every range member still applies, so the row's cells can be read, summed, or formatted as any range, while the row-specific members add the operations that only make sense on a whole row. RowNumber reports the row's position, Height reads or sets how tall it renders, and AutoSizeRow fits that height to content instead, with an overload that controls whether merged cells count toward the measurement. Hidden shows or hides the row, and RemoveRow deletes it, shifting the rows below it up. These edits stay in memory until the parent WorkBook is saved.
using IronXL;
WorkBook workBook = WorkBook.Load("sample.xlsx");
WorkSheet workSheet = workBook.GetWorkSheet("Sheet1");
RangeRow row = workSheet.GetRow(0);
row.AutoSizeRow();
workBook.SaveAs("output.xlsx");The auto resize how-to covers AutoSizeRow, and the add rows and columns how-to inserts and removes rows.
Properties
Height
Gets or sets the height of the row.
Declaration
public int Height { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Hidden
Gets or sets a value indicating whether this row is hidden.
Declaration
public bool Hidden { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
RowNumber
0-based index of the row.
Declaration
public int RowNumber { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Methods
AutoSizeRow()
Changes height of the row to fit the content based on font measurements.
This method measures the text in the cell based on the font that is used for the cell.
If the exact font is not found on the machine, it will try to measure with a default font (Arial).
------------------------------------------------
Usage:
// Auto-size row 5 to fit its content
var workbook = WorkBook.Load("example.xlsx");
var sheet = workbook.DefaultWorkSheet;
var row = sheet.GetRow(5);
row.AutoSizeRow();
workbook.SaveAs("autosized.xlsx");
------------------------------------------------
Declaration
public void AutoSizeRow()
Remarks
Important Considerations:
⚠️ Font Availability: The exact font must be installed on the system for accurate measurements.
📝 Note: This overload does not consider merged cells. Use AutoSizeRow(true) to include merged cells.
Related Documentation:📖 How-To Guide:AutoSize Rows and Columns Guide
📚 API Reference:RangeRow API Documentation
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentException | Thrown when the row cannot be auto-sized. |
| SixLabors.Fonts.FontException | Thrown when no fonts are found installed on the machine. |
AutoSizeRow(Boolean)
Changes height of the row to fit the content based on font measurements.
This method measures the text in the cell based on the font that is used for the cell.
If the exact font is not found on the machine, it will try to measure with a default font (Arial).
------------------------------------------------
Usage:
// Auto-size row 5 including merged cells
var workbook = WorkBook.Load("example.xlsx");
var sheet = workbook.DefaultWorkSheet;
var row = sheet.GetRow(5);
row.AutoSizeRow(true); // Include merged cells
workbook.SaveAs("autosized.xlsx");
------------------------------------------------
Declaration
public void AutoSizeRow(bool useMergedCells)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | useMergedCells | If true, the height of merged cells will be considered. |
Remarks
Important Considerations:
⚠️ Font Availability: The exact font must be installed on the system for accurate measurements.
📝 Merged Cells: When useMergedCells is true, the height calculation considers cells that span multiple rows.
🎯 Wrap Text: If cells have wrap text enabled, the height will be adjusted to show all wrapped content.
Related Documentation:📖 How-To Guide:AutoSize Rows and Columns Guide
📚 API Reference:RangeRow API Documentation
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentException | Thrown when the row cannot be auto-sized. |
| SixLabors.Fonts.FontException | Thrown when no fonts are found installed on the machine. |
RemoveRow()
Removes the row from the worksheet.
Declaration
public void RemoveRow()