Gets only currently allocated cells for this row.
Use this collection if you are reading entire Excel file (you don't know exact position of cells with data). If writing values, using Cells property is recommended.
This collection contains only allocated cells so it is faster as you avoid checking every single cell in a row. You still need to check if a specific cell contains any value (it can be empty).
Following code reads entire XLS file and displays all cells containing any data. Data types are also displayed.
[Visual Basic]
Dim ef As ExcelFile = New ExcelFile("..\TestWorkbook.xls")
Dim sheet As ExcelWorksheet
Dim row As ExcelRow
Dim cell As ExcelCell
For Each sheet In ef.Worksheets
Console.WriteLine("--------- {0} ---------", sheet.Name)
For Each row In sheet.Rows
For Each cell In row.AllocatedCells
If Not cell.Value Is Nothing Then
Console.Write("{0}({1})", cell.Value, cell.Value.GetType().Name)
End If
Console.Write(vbTab)
Next
Console.WriteLine()
Next
Next
[C#]
ExcelFile ef = new ExcelFile("..\\..\\TestWorkbook.xls");
foreach(ExcelWorksheet sheet in ef.Worksheets)
{
Console.WriteLine("--------- {0} ---------", sheet.Name);
foreach(ExcelRow row in sheet.Rows)
{
foreach(ExcelCell cell in row.AllocatedCells)
{
if(cell.Value != null)
Console.Write("{0}({1})", cell.Value, cell.Value.GetType().Name);
Console.Write("\t");
}
Console.WriteLine();
}
}
ExcelRow Class | GemBox.Spreadsheet Namespace | Cells | ExcelCell