0

I have been using linq to excel on one of my projects and it works great !

Its throwing a System.Data.DataException if a sheet in my excel file is blank.This is how i am querying

     var excelInfo = new ExcelQueryFactory(excelFileName);
     var excelRecords = from c in excelInfo.Worksheet<myclass>(sheetname) where c.Result!=null select c;

Also tried this based on a suggestion

  from c in excelInfo.Worksheet<myclass>(sheetname) where c.Result!=null || c.Result!="" select c 

I am getting an error on the 2nd line if the sheet is blank. If i add an header, obviously it works. So how do i check whether the sheet is blank or not before calling that line of code. Or is there any option within linqtoexcel that i am missing to ignore blank sheets?

Thanks!

cableload
  • 4,215
  • 5
  • 36
  • 62

1 Answers1

0

Try also excluding when the value is an empty string:

var excelInfo = new ExcelQueryFactory(excelFileName);
var excelRecords = from c in excelInfo.Worksheet<myclass>(sheetname) where c.Result != null && c.Result != string.Empty select c;
dugas
  • 12,025
  • 3
  • 45
  • 51