Hi,
I have a sheet with a columns that have custom labels. I wish to read the list of rows under a specific column knowing that I won't know the total number rows under that column. My target is to put them in a list.
Thanks
This message was posted using Aspose.Live 2 Forum
Hi,
There are number of ways, e.g The follow sample code extract and fill data to two fields of a datatable from the worksheet.
Workbook book = new Workbook(“e:\test\Book1.xls”);
//Create a datatable with two columns.
DataTable t = new DataTable();
t.Columns.Add(“First”, typeof(string));
t.Columns.Add(“Second”, typeof(string));
System.Data.DataRow dr;
Worksheet worksheet = book.Worksheets[0];
Row row;
for (int i = 0; i <= worksheet.Cells.MaxDataRow; i++)
{
row = worksheet.Cells.Rows[i];
if (!row.IsHidden)
{
dr = t.NewRow();
for (int j = 0; j <= worksheet.Cells.MaxDataColumn; j++)
{
dr[j] = worksheet.Cells[i, j].StringValue;
}
t.Rows.Add(dr);
}
}
MaxDataRow and MaxDataColumn give you the last index(zero based) of the row/column which has data in it.
Alternatively, you may simply loop through the cells and get the values from the cells in the columns.
Thank you.