LinqToExcel icon indicating copy to clipboard operation
LinqToExcel copied to clipboard

Mapping doesn't work

Open bzaar opened this issue 10 years ago • 5 comments

LinqToExcel seems like such a nice idea but it didn't work for me. Sample project: http://morpher.ru/DictionaryCompiler.zip

I am able to get the row value using row [0] but not using a strongly typed mapping. Why?

bzaar avatar May 30 '14 10:05 bzaar

Sorry @bzaar, I don't have time to unzip your solution file. Can you provide a little more context and share the exact lines of code you're using.

paulyoder avatar May 30 '14 11:05 paulyoder

using System;

namespace DictionaryCompiler { public class Row { public string HeadWord; }

class Program
{
    static void Main()
    {
        var xl = new LinqToExcel.ExcelQueryFactory {FileName = @"..\..\Test.xlsx"};

        foreach (var row in xl.Worksheet ())
        {
            Console.WriteLine (row ["HeadWord"]);
        }

        xl.AddMapping <Row> (r => r.HeadWord, "HeadWord");

        foreach (var row in xl.Worksheet <Row> ())
        {
            Console.WriteLine (row.HeadWord ?? "NULL");
        }
    }
}

}

Output:

some test data

NULL NULL NULL NULL NULL Press any key to continue . . .

Expected output:

some test data

some test data NULL NULL Press any key to continue . . .

Hope this helps.

bzaar avatar May 30 '14 11:05 bzaar

yes having the same issue but found that mapping is not working for xlsx files and works in xls. but even in xls, mapping is not accurate. for mapped fields in xls files, data is not fetched and mapped fields are not working in where clause as well. please verify and advise any solution. thanks

isaeed avatar Jun 20 '14 12:06 isaeed

hi isaeed , there might be have some accuracy when having multiple where clause , it better to get the values in memory and include your filtration in memory. i have been used linqtoexcel so much yet i dont have any problem with mapping, if your header name is mapped to the correctly i think u can fetch data.

if your issue persis upload ur excel together .

// i have simple where condition in my xlsx file its working good. if u have filtering try in memory. var faceMechResult = excel.WorksheetRange<ExcelFaceMech>("A5", "AS" + _faceMechRows.ToString(), facemechSheetName). Where(i => i.WorkOrder != null).Select(x => x).ToList();

eldhoabe avatar Jun 20 '14 18:06 eldhoabe

hi eldhoabe , thanks for your suggestion about in memory filtration and things are much improved with it.

isaeed avatar Jun 23 '14 10:06 isaeed