3

I've got an ASP.NET project where I want to adopt LinqToExcel lib. For test purpose I created small class:

public class Point
{
    [ExcelColumn("Stop ID")]
    public int PointID{get;set;}
    [ExcelColumn("Name")]
    public string Name{get;set;}
    [ExcelColumn("Elevation, meters")]
    public float Elevation{get;set;}
}

I've got an excel file containing spreadsheet with data for those Points. I can retrieve them with:

    var query1 = new ExcelQueryFactory(_pathExcelFile).WorksheetRange<Point>  ("C2", "H10000", "Points");
    foreach (var result in query1)
    {
        string name = result.Name;
    }

And it works fine if data is correct in Excel. But if I change let's say Elevation value to any string data with chars(it is float in Point model) the code above is failed on foreach with 'Input string was not in a correct format' exception, and it is System.Format Exception. I need to handle this situation in a way to display informative message why parsing is failed with specific cell coordinates and value it contains. Exception doesn't contain this information. Any ideas how I can achieve this?

andreyfromnn
  • 91
  • 1
  • 4

1 Answers1

1

Let me answer for myself:) Desperating for a quick answer, I went to the sources of this library in GitHub and luckily noticed one of the recent commits named 'Throw Exception with row number and column name/number (#125)' https://github.com/paulyoder/LinqToExcel/commit/ff42b206fdc2ffbe7673eb2b320f5455c7b73720 By description it should satisfied my purpose. Unfortunately this one is not released yet, but I took the sources, compiled by myself and it works! With some minor issues - it shows relative row numbers, but it's work-around-able. So back to my initial question - the current released version of linqtoexcel doesn't support full-info-exceptions, but not-released can be used, hope the guys will release it soon.

andreyfromnn
  • 91
  • 1
  • 4