0

I am trying to use linq-to-excel library, my excel file includes a photo in it and a header about the excel file. I have some new lines in header cells and when I try mapping for my model and excel headers I always get NULL values. Should I do anything else about newlines or can it handle it for me?

Here is my model for excel file:

public class DefectivePartModel
{
    public string ServiceCode { get; set; }
    public string ServiceName { get; set; }
    public string KleymNo { get; set; }
    public string DefectivePartName { get; set; }
    public string DefectivePartCode { get; set; }
    public double Amount { get; set; }
    public string RepairPeriod { get; set; }
    public int DispatchNoteNo { get; set; }
    public DateTime DispatchNoteDate { get; set; }
    public string AddressedCompany { get; set; }
}

and excel parser:

public class ExcelParser
{
    public ExcelParser(string filePath)
    {
        var excel = new ExcelQueryFactory(filePath);
        excel.AddMapping<DefectivePartModel>(x => x.ServiceCode, "Servis"+Environment.NewLine+"Kod");
        excel.AddMapping<DefectivePartModel>(x => x.ServiceName, @"Servis Ad");
        excel.AddMapping<DefectivePartModel>(x => x.KleymNo, @"Kleym No");
        excel.AddMapping<DefectivePartModel>(x => x.DefectivePartCode, @"Arızalı \r\nParça Kodu");
        excel.AddMapping<DefectivePartModel>(x => x.DefectivePartName, @"Arızalı Parça Adı");
        excel.AddMapping<DefectivePartModel>(x => x.Amount, @"Adet");
        excel.AddMapping<DefectivePartModel>(x => x.RepairPeriod, @"Onarım \r\nDönemi");
        excel.AddMapping<DefectivePartModel>(x => x.DispatchNoteNo, @"İrsaliye No");
        excel.AddMapping<DefectivePartModel>(x => x.DispatchNoteDate, @"İrsaliye \r\nTarihi");
        excel.AddMapping<DefectivePartModel>(x => x.AddressedCompany, @"Gönderilen \r\nFirma/Yer");

        var parts = from c in excel.Worksheet<DefectivePartModel>("ServisArizaliParcaGonderimRapor")
                    select c;

    }
}
sborfedor
  • 316
  • 1
  • 9
  • 24
  • Can you provide more information about the library you are using? – jcwrequests Sep 21 '13 at 23:08
  • it's linqtoexcel: https://github.com/paulyoder/LinqToExcel – ibrahim yılmaz Sep 21 '13 at 23:10
  • Do you have an example of your excel file – Paul Sep 21 '13 at 23:23
  • Looks like an interesting project. Here is my advice download the the solution from github and add it directly to your solution the step through the code to determine what is causing in issue. The other piece of advice is contact Paul Yoder directly paulyoder@gmail.com since he wrote the library he would probably answer your question better than anyone. Most Open Source Author are really helpful and approachable so give it a shot. Thanks for sharing I want to check this out myself. Good Luck – jcwrequests Sep 21 '13 at 23:24
  • Here is my excel file: https://www.dropbox.com/s/p7hdbs1peyc8mh6/Haziran-2012.xls – ibrahim yılmaz Sep 21 '13 at 23:25
  • @jcwrequests thanks for advice, i've sent him an email, i hope that helps. – ibrahim yılmaz Sep 21 '13 at 23:46
  • 1
    Try changing "\r\n" to a underscore _ where the newlines are. See this: https://code.google.com/p/linqtoexcel/issues/detail?id=6 – aup Jul 30 '15 at 22:56

0 Answers0