C# 启用数据列表的Linq到Excel映射Excel单元格
我能够使用下面的LinqtoExcel映射概念解析excel文件中的大量数据 我的要求: 当电子表格中的特定单元格提供了数据列表选项时,如何进行LinqtoExcel映射。是否可以按如下所示对场景进行映射C# 启用数据列表的Linq到Excel映射Excel单元格,c#,excel,linq,linq-to-excel,C#,Excel,Linq,Linq To Excel,我能够使用下面的LinqtoExcel映射概念解析excel文件中的大量数据 我的要求: 当电子表格中的特定单元格提供了数据列表选项时,如何进行LinqtoExcel映射。是否可以按如下所示对场景进行映射 excel.AddMapping<RESULT_DBML>(x => x.Period_Name, "Period_Name" OR "Prd_Date"); 我的C代码: class Reference { public string Period_Name {
excel.AddMapping<RESULT_DBML>(x => x.Period_Name, "Period_Name" OR "Prd_Date");
我的C代码:
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;
}