1.Excel为03版
protected DataTable ExceltoDataTabale()
{
string filepath = Server.MapPath("~/") + "excel/PROVINCE.xls";
string constr = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Jet OLEDB:Engine Type=35;Extended Properties=Excel 8.0;Persist Security Info=False", filepath);
DataTable dt = new DataTable();
string tablename;
DataSet ds = new DataSet();
using (OleDbConnection connection = new OleDbConnection(constr))
{
connection.Open();
dt = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
tablename = dt.Rows[0]["Table_Name"].ToString();
OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * FROM [" + tablename + "]", connection);
oda.Fill(ds, tablename);
connection.Close();
}
return ds.Tables[tablename];
}
2.Excel为07版
Provider=Microsoft.ACE.OLEDB.12.0