paulyoder / LinqToExcel

Use LINQ to retrieve data from spreadsheets and csv files
MIT License
1.06k stars 299 forks source link

LinqToExcel Not Parsing Date #118

Closed rubyhaus closed 6 years ago

rubyhaus commented 7 years ago

I posted this on SO, but haven't had any luck so hopefully someone here can help me.

I am working with a client to import a rather larger Excel file (over 37K rows) into a custom system and utilizing the excellent LinqToExcel library to do so. While reading all of the data in, I noticed it was breaking on records about 80% in and dug a little further. The reason it fails is the majority of records (with associated dates ranging 2011 - 2015) are normal, e.g. 1/3/2015, however starting in 2016, the structure changes to look like this: '1/4/2016 (note the "tick" at the beginning of the date) and LinqToExcel starts returning a DBNull for that column.

Here is a small code snippet:

var excel = new LinqToExcel.ExcelQueryFactory(Path.Combine(this.FilePath, this.CurrentFilename)); foreach (var row in excel.Worksheet(file.WorksheetName)) { //the "row" variable here, which is a LinqToExcel.Row instance, doesn't have the value - it's empty data.Add(this.FillEntity(row)); }

Any ideas on why it would do that and ways around it? Note that this isn't a casting issue - I can use the Immediate Window to see all the values of the LinqToExcel.Row value and where that column index is, the value is empty. I'm also not using generics to fill the class - the value isn't filled by LinqToExcel itself, so I'm not sure where to begin on resolving that.

rubyhaus commented 7 years ago

Found it! See full details here: https://stackoverflow.com/questions/45314971/linqtoexcel-not-parsing-date/45356099