LinqToExcel icon indicating copy to clipboard operation
LinqToExcel copied to clipboard

How about add new function to clean mapping data

Open VickyHuang07 opened this issue 8 years ago • 3 comments

Due to an excel file contains many sheets, there exists same property but shows as different header name.

Example: When Sheet 1 .

Column 1 Column 2 AMOUNT
Text Text 9

excel.addMapping<ClassA>(A=>A.RATE,"AMOUNT"); ... Sheet 1 done.

Next Sheet 2.

Column 1 RATE Column 3
Text 8 Text

Due to header have RATE which equal to ClassB. I think it will auto mapping. After use excel.worksheet<ClassB>(Sheet2) ClassB's RATE is null due to it's mapping to "AMOUNT".

This is what i encounter.

Is it possible add new function to clean the certain one or all mapping?

VickyHuang07 avatar Oct 02 '17 07:10 VickyHuang07

The "easy" way to do this now would be to just re-initialize excel again with excel = new ExcelQueryFactory("excelFileName"); which would have a result similar to clearing all existing mappings.

mrworkman avatar Oct 02 '17 17:10 mrworkman

Thank for this tool. It save me a lot of time about processing Excel file. And I encounter the problem like this one. In current practice, it take almost 4 secs to execute new ExcelQueryFactory each time.

My Sample like below.

For Sheet 1 excel.addMapping<ClassA>(x=>x.Property,"Column A",x=>{ logic A }); For Sheet 2 excel.addMapping<ClassB>(x=>x.Property,"Column A",x=>{ logic B }); // this will cause error Exception {"An item with the same key has already been added."}

Sheet 1 and Sheet 2 have same column but with different logic. And this kind of situation happens very often in my case. Although it's ok to use new ExcelQueryFactory. but I think it's not a long term solution due to the high cost.

Off-DutY avatar Jul 06 '18 06:07 Off-DutY

Another option might be to do the mapping using annotations which were added in #34.

The issue experienced here sounds similar to another issue fixed by #90. I will look into it.

mrworkman avatar Aug 26 '18 05:08 mrworkman