public DataSet GetList(string filePath){
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + filePath + ";Extended Properties='Excel 11.0;HDR=NO;IMEX=1'";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
string strExcel = "";
OleDbDataAdapter mycmd = null;
DataSet ds = null;
strExcel = "select *from [sheet1$]";
mycmd = new OleDbDataAdapter(strExcel, strConn);
ds = new DataSet();
mycmd.Fill(ds, "table1");
return ds;
}
protected void Page_Load(object sender, EventArgs e)
{
datagridview.datasource=GetList("excel.xls");
datagridview.databind();
}
是不是这样的。。。。
d