[C#] 纯文本查看 复制代码 publicDataSet ImportExcel(string strFileName) //strFileName指定的路径+文件名.xls
{
if (strFileName != "")
{
string conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFileName + ";Extended Properties=Excel 8.0";
string sql = "select * from [Sheet1$]";
OleDbDataAdapter da = newOleDbDataAdapter(sql, conn);
DataSet ds = newDataSet();
try
{
da.Fill(ds, "datatable");
}
catch
{
}
return ds;
}
else
{
return null;
}
}
这个是吧Excel转成 DataSet, 你在吧DataSet转成DataTable
然后把DataTable 插到数据库就行了 |