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!
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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.