将Execl表中的数据导入到DataTable或List中在页面显示,点击确认后在保存到数据库
先保存到库,然后从库中取
Excel是一张二维表,可以操作其中的任何数据!
private DataSet xsldata(string filepath, int type)
{
//HDR标识是否有表头,IMEX标识格式是文本
string strCon = "";
if (type == 1) //Execl2007、2010版本
strCon = "Provider=Microsoft.Ace.OleDb.12.0;Data Source=" + filepath + ";Extended Properties='Excel 12.0;HDR=Yes;IMEX=1;'";
else //Execl2003版本
strCon = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + filepath + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";
System.Data.OleDb.OleDbConnection Conn = new System.Data.OleDb.OleDbConnection(strCon);
string strCom = "SELECT * FROM [Sheet1$]";
Conn.Open();
System.Data.OleDb.OleDbDataAdapter myCommand = new System.Data.OleDb.OleDbDataAdapter(strCom, Conn);
DataSet ds = new DataSet();
myCommand.Fill(ds, "ds");
Conn.Close();
return ds;
}