Gets only currently allocated cells for this row.
Namespace: GemBox.SpreadsheetAssembly: GemBox.Spreadsheet (in GemBox.Spreadsheet.dll) Version: 37.3.30.1035
public ExcelCellCollection AllocatedCells { get; }Public ReadOnly Property AllocatedCells As ExcelCellCollection
Get
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 XLSX file and displays all cells containing any data. Data types are also displayed.
ExcelFile ef = ExcelFile.Load("Book1.xlsx");
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();
}
}ExcelFile ef = ExcelFile.Load("Book1.xlsx");
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();
}
}Dim ef As ExcelFile = ExcelFile.Load("Book1.xlsx")
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
NextDim ef As ExcelFile = ExcelFile.Load("Book1.xlsx")
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