I am able to parse the huge set of data from the excel file using the below LinqtoExcel mapping concepts.
My requirement: How to do LinqtoExcel Mapping when a particular cell in spreadsheet is provided with DataLists options. Is it possible to do for mapping scenario as illustrated below
excel.AddMapping<RESULT_DBML>(x => x.Period_Name, "Period_Name" OR "Prd_Date");
My C# code:
class Reference
{
public string Period_Name { get; set; }
public string Start_Time { get; set; }
public string End_Time { get; set; }
}
private static bool import_excelres(string _path)
{
bool parse_status = false;
List<string> files = System.IO.Directory.GetFiles(@_path, "*.xlsx", SearchOption.AllDirectories).ToList<string>();
DataClasses1DataContext dbContext = new DataClasses1DataContext();
ExcelQueryFactory excel = new ExcelQueryFactory();
excel.FileName = files.ElementAt(0);
// Mapping Excel Columns to Database Table Results with Table Column Names
excel.AddMapping<RESULT_DBML>(x => x.Period_Name, "Period_Name");
excel.AddMapping<RESULT_DBML>(x => x.Start_Time, "Start_Time");
excel.AddMapping<RESULT_DBML>(x => x.End_Time, "End_Time");
var results = (from x in excel.Worksheet<Reference>("Sheet1")
select new RESULT_DBML
{
Period_Name = x.Period_Name,
Start_Time = x.Start_Time,
End_Time = x.End_Time,
});
dbContext.RESULT_DBMLs.InsertAllOnSubmit(results);
dbContext.SubmitChanges();
return parse_status;
}