paulyoder / LinqToExcel

Use LINQ to retrieve data from spreadsheets and csv files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AddMapping is not working - column name is too long (over 64 characters)

tomaspaul opened this issue · comments

Hello, I have this simple object in C#:

public class Result
{
    public string SampleId { get; set; }
    public string RawValue { get; set; }
    public string Dilution { get; set; }
    public string InstrumentMethod { get; set; }
}

I use mappings bellow:

var excel = new ExcelQueryFactory(_filePath);
excel.AddMapping<Result>(x => x.SampleId, "Identity");
excel.AddMapping<Result>(x => x.RawValue, "Calibrated Result (mg/L) with blank correction  and Dilution Factor");
excel.AddMapping<Result>(x => x.Dilution, "Total dilution factor");
excel.AddMapping<Result>(x => x.InstrumentMethod, "Method");
results = (from r in excel.Worksheet<Result>("COD") select r).ToList();

The issue is that values from column with name "Calibrated Result (mg/L) with blank correction and Dilution Factor" is not loaded. The other columns are fine.

Here is the source file:
190826_COD_1.xlsx

If you have any idea what causes this issue, please let me know.

Kind Regards,
Tomas

It looks like there is a 64 character limit to column names when using Jet/ACE to read from excel spreadsheets. Try using Calibrated Result (mg/L) with blank correction and Dilution Fac as the column name in your code instead. It worked in my case:

excel.AddMapping<Result>(x => x.RawValue, "Calibrated Result (mg/L) with blank correction  and Dilution Fac");

Hi Stephen @mrworkman, many thanks for your tip! It works excellent with shortened column name in my project too. Issue solved.