Hello,
I found strange thing. I have Excel file and I need to enumerate all cells to get values and process them.
for (int i = 1; i < sheet.Rows.Length + 1; i++)
for (int j = 1; j < sheet.Columns.Length + 1; j++)
{
var value = sheet[i, j].Value;
}
Looks fine, but sometimes "sheet.Columns" is wrong. Excel has 47 columns and property shows 45, so some columns are not processed.
I found that there is another property - sheet.UsedRange.LastColumn and value is 47.
And sheet .Columns.Length == 45 and sheet.Columnss.Length == 47.
So what is proper way to enumerate cells per row/col? Why both values are different?
Regards
René
|
IWorksheet sheet = workbook.Worksheets[0];
IMigrantRange migrantRange = sheet.MigrantRange;
int rowCount = sheet.UsedRange.LastRow;
int colCount = sheet.UsedRange.LastColumn;
for (int i = 1; i <= rowCount; i++)
{
for (int j = 1; j <= colCount; j++)
{
migrantRange.ResetRowColumn(i,j);
string value = migrantRange.Value;
}
} |