First, I would determine how many lines are actually used:
Excel.Range allCellsInColumn = xlWorksheet.Range["A:A"]; Excel.Range usedCells = allCellsInColumn.Find("*", Missing.Value, Missing.Value, Missing.Value, Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlPrevious, false, Missing.Value, Missing.Value);
After that, you can get the values:
System.Array values = usedCells.Values;
Once you have the values ββin the array, you can skip elements that have nothing. I donβt think there is a way to get only cells with something in them, without looping them one at a time, which is very laborious in Interop.
source share