我没有用c#读取过Excel,有没有谁能有一套完整的代码可以参考一下,万分感谢~~
OleDbConnection cn = new OleDbConnection("Provider=Microsoft.Ace.OleDb.12.0; Data Source=" + accessPath + ";");
try
{
OleDbDataAdapter da = new OleDbDataAdapter(sql, cn);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
da.Fill(ds, srcTable);
dt = ds.Tables[0].Copy();
return dt;
}
catch (Exception ex)
{
string e = ex.StackTrace;
// Log.error(e);
cn.Close();
return null;
}
finally
{
cn.Close();
}