var fileName = string.Format("{0}\fileNameHere", Directory.GetCurrentDirectory());var connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=Excel 8.0;", fileName);var adapter = new OleDbDataAdapter("SELECt * FROM [workSheetNameHere$]", connectionString);var ds = new DataSet();adapter.Fill(ds, "anyNameHere");DataTable data = ds.Tables["anyNameHere"];
这就是我通常使用的。这有点不同,因为我通常在表的编辑中粘贴一个AsEnumerable():
var data = ds.Tables["anyNameHere"].AsEnumerable();
var query = data.Where(x => x.Field<string>("phoneNumber") != string.Empty).Select(x => new MyContact { firstName= x.Field<string>("First Name"), lastName = x.Field<string>("Last Name"), phoneNumber =x.Field<string>("Phone Number"), });
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)