AUTHOR: Peter Milchev
DATE POSTED: January 21, 2019
For performance optimization, the cells and rows might not be the in the same order as they work in the displayed spreadsheet. Also, the empty cells are not included in the Cells and Rows collections of a sheet. With that said, the conventional iteration might not work properly.
The Cell and Row have a .Index property that allows you to determine the real location in the Sheet. For convenience, we can use LINQ Methods to find the cell by Index:
var sheet = workbook.Sheets[0];
var rowIndex = 3;
var row = sheet.Rows.FirstOrDefault(r => r.Index == rowIndex);
if
(row !=
null
)
{
var cellIndex = 3;
var cell = row.Cells.FirstOrDefault(c => c.Index == cellIndex);
(cell !=
var value = cell.Value;
}
Resources Buy Try