Class Row
Namespace: Aspose.Cells
Assembly: Aspose.Cells.dll (25.2.0)
Represents a single row in a worksheet.
public class Row : IEnumerable
Inheritance
Implements
Inherited Members
object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Examples
csharp
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
Style style = workbook.CreateStyle();
//Setting the background color to Blue
style.BackgroundColor = Color.Blue;
//Setting the foreground color to Red
style.ForegroundColor= Color.Red;
//setting Background Pattern
style.Pattern = BackgroundType.DiagonalStripe;
//New Style Flag
StyleFlag styleFlag = new StyleFlag();
//Set All Styles
styleFlag.All = true;
//Get first row
Row row = worksheet.Cells.Rows[0];
//Apply Style to first row
row.ApplyStyle(style, styleFlag);
//Saving the Excel file
workbook.Save("book1.xls");
'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Obtaining the reference of the first worksheet
Dim worksheet As Worksheet = workbook.Worksheets(0)
Dim style As Style = workbook.CreateStyle()
'Setting the background color to Blue
style.BackgroundColor = Color.Blue
'Setting the foreground color to Red
style.ForegroundColor = Color.Red
'setting Background Pattern
style.Pattern = BackgroundType.DiagonalStripe
'New Style Flag
Dim styleFlag As New StyleFlag()
'Set All Styles
styleFlag.All = True
'Get first row
Dim row as Row = worksheet.Cells.Rows(0)
'Apply Style to first row
row.ApplyStyle(style, styleFlag)
'Saving the Excel file
workbook.Save("book1.xls")
Properties
FirstCell
Gets the first cell object in the row.
public Cell FirstCell { get; }
Property Value
FirstDataCell
Gets the first non-blank cell in the row.
public Cell FirstDataCell { get; }
Property Value
GroupLevel
Gets the group level of the row.
public byte GroupLevel { get; set; }
Property Value
HasCustomStyle
Indicates whether this row has custom style settings(different from the default one inherited from workbook).
public bool HasCustomStyle { get; }
Property Value
Height
Gets and sets the row height in unit of Points.
public double Height { get; set; }
Property Value
Index
Gets the index of this row.
public int Index { get; }
Property Value
IsBlank
Indicates whether the row contains any data
public bool IsBlank { get; }
Property Value
IsCollapsed
whether the row is collapsed
public bool IsCollapsed { get; set; }
Property Value
IsHeightMatched
Indicates whether the row height matches current default font setting of the workbook. True of this property also denotes the row height is “automatic” without custom height value set by user.
public bool IsHeightMatched { get; set; }
Property Value
Remarks
When this property is true, if the content in this row changes, generally the row height needs to be re-calculated(such as by Aspose.Cells.Worksheet.AutoFitRows) to get the same result with what is shown in ms excel when you opening the workbook in it.
IsHidden
Indicates whether the row is hidden.
public bool IsHidden { get; set; }
Property Value
LastCell
Gets the last cell object in the row.
public Cell LastCell { get; }
Property Value
LastDataCell
Gets the last non-blank cell in the row.
public Cell LastDataCell { get; }
Property Value
this[int]
Gets the cell.
public Cell this[int column] { get; }
Property Value
Methods
ApplyStyle(Style, StyleFlag)
Applies formats for a whole row.
public void ApplyStyle(Style style, StyleFlag flag)
Parameters
style
Style
The style object which will be applied.
flag
StyleFlag
Flags which indicates applied formatting properties.
CopySettings(Row, bool)
Copy settings of row, such as style, height, visibility, …etc.
public void CopySettings(Row source, bool checkStyle)
Parameters
source
Row
the source row whose settings will be copied to this one
checkStyle
bool
whether check and gather style. Only takes effect and be needed when two row objects belong to different workbook and the styles of two workbooks are different.
Equals(object)
Checks whether this object refers to the same row with another.
public override bool Equals(object obj)
Parameters
obj
object
another object
Returns
true if two objects refers to the same row.
Equals(Row)
Checks whether this object refers to the same row with another row object.
public bool Equals(Row row)
Parameters
row
Row
another row object
Returns
true if two row objects refers to the same row.
GetCellByIndex(int)
Get the cell by specific index in the cells collection of this row.
public Cell GetCellByIndex(int index)
Parameters
index
int
The index(position) of the cell in the cells collection of this row.
Returns
The Cell object at given position.
Remarks
To traverse all cells in sequence without modification, using Aspose.Cells.Row.GetEnumerator will give better performance than using this method to get cell one by one.
GetCellOrNull(int)
Gets the cell or null in the specific index.
public Cell GetCellOrNull(int column)
Parameters
column
int
The column index
Returns
Returns the cell object if the cell exists. Or returns null if the cell object does not exist.
GetEnumerator()
Gets the cells enumerator
public IEnumerator GetEnumerator()
Returns
The cells enumerator
Examples
csharp
[C#]
Workbook workbook = new Workbook("template.xlsx");
Cells cells = workbook.Worksheets[0].Cells;
IEnumerator en = cells.Rows[1].GetEnumerator();
while (en.MoveNext())
{
Cell cell = (Cell)en.Current;
Console.WriteLine(cell.Name + ": " + cell.Value);
}
GetEnumerator(bool, bool)
Gets an enumerator that iterates cells through this row.
public IEnumerator GetEnumerator(bool reversed, bool sync)
Parameters
reversed
bool
whether enumerate cells in reversed order
sync
bool
whether the returned enumerator should check the modification of cells in this row and keep synchronized with it.
Returns
The cell enumerator
Remarks
If the row will be modified(by operations that may cause new Cell be instantiated or existing Cell be removed) during the traversal with the enumerator, synchronized enumerator should be used instead of normal enumerator so that the traversal can continue from the position just after the one has been traversed by the last MoveNext(). However, together with the advantage that no element be skipped or traversed repeatedly, the disadvantage for synchronized enumerator is that the performance will be degraded a bit when comparing with normal enumerator.
GetStyle()
Gets the style of this row.
public Style GetStyle()
Returns
Remarks
Modifying the returned style object directly takes no effect for this row or any cells in this row.
You have to call Aspose.Cells.Row.ApplyStyle(Aspose.Cells.Style,Aspose.Cells.StyleFlag) or Aspose.Cells.Row.SetStyle(Aspose.Cells.Style) method
to apply the change to this row.
Row’s style is the style which will be inherited by cells in this row(those cells that have no custom style settings,
such as existing cells that have not been set style explicitly, or those that have not been instantiated)
SetStyle(Style)
Sets the style of this row.
public void SetStyle(Style style)
Parameters
style
Style
the style to be used as the default style for cells in this row.
Remarks
This method only sets the given style as the default style for this row, without changing the style settings for existing cells in this row. To update style settings of existing cells to the specified style at the same time, please use Aspose.Cells.Row.ApplyStyle(Aspose.Cells.Style,Aspose.Cells.StyleFlag)