paulyoder / LinqToExcel

Use LINQ to retrieve data from spreadsheets and csv files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Failure to map columns with square brackets in the header row

JeremyMahieu opened this issue · comments

I have an excel that looks like in the screenshot.
image
TestFileHeaders.xlsx

My mapping class looks like this.

public class UnitExcelRow
    {
        [ExcelColumn("barcode")]
        public string Barcode { get; set; }

        [ExcelColumn("gross [ kg]")]
        public string GrossWeight { get; set; }
    }

And the code looks like this:

var unitRaw = excel.Worksheet<UnitExcelRow>(0) // 0 for first worksheet<
  .ToList(); 

I only get null for GrossWeight. I'm not sure why it's not working, if I change the header to "test" it works. I assume it's the square brackets that are not working.

In a similar vein, I have a column header "Date/Time" and when I trying to select and filter on that column "from c in worksheet where c["Date/Time"] <... it comes back with an error that "..."Date/Time" is not a valid column name. Valid column names are... xxx, "Date/Time", yyy..."