Class Row
Contents
[
Hide
]Row class
Represents a single row in a worksheet.
public class Row : IEnumerable
Properties
Name | Description |
---|---|
FirstCell { get; } | Gets the first cell object in the row. |
FirstDataCell { get; } | Gets the first non-blank cell in the row. |
GroupLevel { get; set; } | Gets the group level of the row. |
HasCustomStyle { get; } | Indicates whether this row has custom style settings(different from the default one inherited from workbook). |
Height { get; set; } | Gets and sets the row height in unit of Points. |
Index { get; } | Gets the index of this row. |
IsBlank { get; } | Indicates whether the row contains any data |
IsCollapsed { get; set; } | whether the row is collapsed |
IsHeightMatched { get; set; } | 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. |
IsHidden { get; set; } | Indicates whether the row is hidden. |
Item { get; } | Gets the cell. |
LastCell { get; } | Gets the last cell object in the row. |
LastDataCell { get; } | Gets the last non-blank cell in the row. |
Methods
Name | Description |
---|---|
ApplyStyle(Style, StyleFlag) | Applies formats for a whole row. |
CopySettings(Row, bool) | Copy settings of row, such as style, height, visibility, …etc. |
override Equals(object) | Checks whether this object refers to the same row with another. |
Equals(Row) | Checks whether this object refers to the same row with another row object. |
GetCellByIndex(int) | Get the cell by specific index in the cells collection of this row. |
GetCellOrNull(int) | Gets the cell or null in the specific index. |
GetEnumerator() | Gets the cells enumerator |
GetEnumerator(bool, bool) | Gets an enumerator that iterates cells through this row. |
GetStyle() | Gets the style of this row. |
SetStyle(Style) | Sets the style of this row. |
Examples
namespace AsposeCellsExamples
{
using Aspose.Cells;
using System;
using System.Drawing;
using System.Collections;
public class RowDemo
{
public static void RowExample()
{
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Create a style object
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);
// Setting row properties
row.Height = 20.0;
row.IsHidden = false;
row.IsCollapsed = false;
row.GroupLevel = 1;
row.IsHeightMatched = true;
// Accessing cells in the row
Cell firstCell = row.FirstCell;
Cell firstDataCell = row.FirstDataCell;
Cell lastCell = row.LastCell;
Cell lastDataCell = row.LastDataCell;
// Checking if the row is blank
bool isBlank = row.IsBlank;
// Checking if the row has custom style
bool hasCustomStyle = row.HasCustomStyle;
// Getting the index of the row
int rowIndex = row.Index;
// Getting a cell by index
Cell cellByIndex = row.GetCellByIndex(0);
// Getting the style of the row
Style rowStyle = row.GetStyle();
// Setting the style of the row
row.SetStyle(rowStyle);
// Copying settings from another row
Row sourceRow = worksheet.Cells.Rows[1];
row.CopySettings(sourceRow, true);
// Enumerating through cells in the row
IEnumerator cellEnumerator = row.GetEnumerator();
while (cellEnumerator.MoveNext())
{
Cell cell = (Cell)cellEnumerator.Current;
Console.WriteLine(cell.Name + ": " + cell.Value);
}
// Saving the Excel file
workbook.Save("RowExample.xlsx");
}
}
}
See Also
- namespace Aspose.Cells
- assembly Aspose.Cells