c# - LinqToExcel Duplicate Column Names -


i have machine generated excel file has few columns same name. e.g.:

        b          c       d group 1           group 2 period | name     period | name  

and got dto this:

[excelcolumn("period")] public string firstperiod { get; set; } [excelcolumn("name")] public string firstname { get; set; }  [excelcolumn("period")] public string secondperiod { get; set; } [excelcolumn("name")] public string secondname { get; set; } 

i use following command read lines:

var excel = new excelqueryfactory(filepath); excel.worksheetrange<t>(begincell, endcoll + linescount.tostring(), sheetindex); 

it reads file fine, when check content of dto saw 'second' properties have same values of 'first' ones.

this post closest thing found in searches , think problem solved this:

excel.addmapping<mydto>(x => x.firstperiod, "a"); excel.addmapping<mydto>(x => x.firstname, "b"); excel.addmapping<mydto>(x => x.secondperiod, "c"); excel.addmapping<mydto>(x => x.secondname, "d"); 

but don't know how excel column letters...

obs: got few more code behind don't think relevant problem.

the problem you're having not possible solve today linqtoexcel because wraps oledb functions , map properties based on columns names, lose oledb options "fn" specify columns (like "f1" "a").

there's issue on linqtoexcel github repo this. https://github.com/paulyoder/linqtoexcel/issues/85

i recommend change name of columns not duplicates names (e.g. period1, name1, period2, name2) if it's not possible change because machine generated, try change header names in runtime.

another option make more 1 query in excel file, ranges splitted groups , merging results later.

var excel = new excelqueryfactory(filepath); var group1 = excel.worksheetrange<t>(a1, b + rowcount); var group2 = excel.worksheetrange<t>(c1, d + rowcount); 

edit: i'll work on feature try solve problem in elegant manner, maybe in future have more flexible option map columns , properties (if accept pull request)


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -