简体   繁体   English

LINQ到Excel不忽略空白表

[英]linq to excel not ignoring blank sheet

I have been using linq to excel on one of my projects and it works great ! 我一直在使用linq在我的一个项目中表现出色,效果很好!

Its throwing a System.Data.DataException if a sheet in my excel file is blank.This is how i am querying 如果我的Excel文件中的工作表为空白,则抛出System.Data.DataException。这就是我查询的方式

     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? 还是linqtoexcel中有什么我错过忽略空白纸的选项?

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM