Get value from the last non empty cell in an excel row

@Sripadraj
It would be easier to get it from Sheet1, before it’s split:

foreach (row in dt)
{
	string lastCell = row(0).ToString().Split(","c).Last()
}

@ranjith
Probably you could, but I don’t think it’s worth the trouble.
It’s clearer to just use a normal loop.

That said:
row(col) is nothing or row(col).Equals("")
There’s a better way to test for null or empty:
String.IsNullOrEmpty(row(col))

Another thing is that or operator tests both sides, which means that if your second check involves a method call and the object is null, it will still throw a null reference. Use OrElse in these situations.
See here for more info.

3 Likes