public static DataSet ReadExcel(string filepath, string sheetName)
{
try
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath + ";Extended Properties='Excel 8.0;HDR=False;IMEX=1'";
OleDbConnection oleConn = new OleDbConnection(strConn);
oleConn.Open();
string sql = "select * from [" + sheetName + "$]";
OleDbDataAdapter oleDaExcel = new OleDbDataAdapter(sql, oleConn);
DataSet oleDsExcel = new DataSet();
oleDaExcel.Fill(oleDsExcel, "table1");
oleConn.Close();
return oleDsExcel;
}
catch (Exception e)
{
return null;
throw;
}
}
C# 读取EXCEL文件数据
最新推荐文章于 2024-11-16 10:18:22 发布