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;
}
}