I use LinqToExcel in my applications but cannot figure the best way to dynamically set the end range when reading data. We currently use an arbitrarily large value e.g. 30000 but this only ok when I'm sure the range won't exceed a certain value.
Aside from incrementally checking each sequential row for content is there any better way to dynamically determine the endrange when using LinqToExcel? Here's my current (untested) solution:
Private Function GetPreviousUnquoted() As Integer
Dim MFIDColumn As String = "E:"
Dim row As Integer = 9
Dim data As Boolean = True
Dim excel = New ExcelQueryFactory(_PathAndName)
Do Until data = False
Dim unquotedQuery = From item In excel.WorksheetRange(
MFIDColumn & row, MFIDColumn & row, 1)
Select item
If unquotedQuery.FirstOrDefault.Item(0).ToString.Length > 0 Then
row += 1
data = True
Else
data = False
End If
Loop
Return row
End Function