I have an excel file that has 3 columns. So I created a model like following to cast rows.
public class Point
{
[ExcelColumn("Lon")]
public float Lon {get;set;}
[ExcelColumn("Lat")]
public float Lat {get;set;}
[ExcelColumn("Elevation")]
public float Elevation {get;set;}
}
var excel = new ExcelQueryFactory("points.xlsx");
var ic= from c in excel.Worksheet<Point>();
Sample excel
Lon Lat Elevation
--- --- ---------
11.5 25.6 80.56
12ab 89.87 14.83
1.7 5.8 9.3
But sometimes users may incorrect data entry. For example Lon value is "12ab" for 2nd row. In this stuation throws exception.
How can I understand which row and which cell is failed?
Not really what you wanted but maybe it is enough of a "solution" for you.
Couldn't find a way with the current version of the Library, but I did the following
If you don't mind using the "pre-release" version https://www.nuget.org/packages/LinqToExcel/2.0.0-PRERELEASE-2
You could do it like this:
This uses the "Lazy" feature, which got included in October 2018 but up till now there was never a NuGet package released. https://github.com/paulyoder/LinqToExcel/pull/155
You actually don't even need the manual count of
rowNumberwith the pre-release version since there is a second code change that comes in handy for you, which also never got published in a final version, https://github.com/paulyoder/LinqToExcel/pull/125 (from October 2017)So all you would need to do is:
And you would get the new and improved exception stating something like this: