Class RowCollection
Contents
[
Hide
]RowCollection class
Collects the Row
objects that represent the individual rows in a worksheet.
public class RowCollection : IEnumerable
Properties
Name | Description |
---|---|
Count { get; } | Gets the number of rows in this collection. |
Item { get; } | Gets a Row object by given row index. The Row object of given row index will be instantiated if it does not exist before. |
Methods
Name | Description |
---|---|
Clear() | Clear all rows and cells. |
GetEnumerator() | Gets an enumerator that iterates rows through this collection |
GetEnumerator(bool, bool) | Gets an enumerator that iterates rows through this collection |
GetRowByIndex(int) | Gets the row object by the position in the list. |
RemoveAt(int) | Remove the row item at the specified index(position) in this collection. |
Examples
namespace AsposeCellsExamples
{
using Aspose.Cells;
using System;
using System.Collections;
public class RowCollectionDemo
{
public static void RowCollectionExample()
{
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
worksheet.Cells["A1"].PutValue("Hello");
worksheet.Cells["A2"].PutValue("World");
worksheet.Cells["A3"].PutValue("Aspose.Cells");
// Get the Rows collection
RowCollection rows = worksheet.Cells.Rows;
// Get the number of rows in the collection
int rowCount = rows.Count;
Console.WriteLine("Number of rows: " + rowCount);
// Get the first row
Row firstRow = rows[0];
Console.WriteLine("First row index: " + firstRow.Index);
// Iterate through the rows using GetEnumerator
IEnumerator enumerator = rows.GetEnumerator();
while (enumerator.MoveNext())
{
Row row = (Row)enumerator.Current;
Console.WriteLine("Row index: " + row.Index + ", Height: " + row.Height);
}
// Get a row by index
Row specificRow = rows.GetRowByIndex(1);
Console.WriteLine("Specific row index: " + specificRow.Index);
// Clear all rows and cells
rows.Clear();
Console.WriteLine("Rows cleared.");
// Save the workbook
workbook.Save("RowCollectionExample.xlsx");
}
}
}
See Also
- namespace Aspose.Cells
- assembly Aspose.Cells