命名空间using System.Data.OleDb;
private void excelRead()
{
string pathExcel="haha.xls"; //excel路径
//读取Excel
pathExcel=Server.MapPath(pathExcel);
string myString="Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = '" +pathExcel+"';Extended Properties=Excel 8.0";
OleDbConnection cnnXls = new OleDbConnection(myString);
string sqlInBox="select*from [sheet1$]";
OleDbDataAdapter drInBox=new OleDbDataAdapter(sqlInBox,cnnXls);
DataSet dsInBox=new DataSet();
drInBox.Fill(dsInBox);
if(dsInBox.Tables[0].Rows.Count>0)
{
for(int i=0;i<dsInBox.Tables[0].Rows.Count;i++)
{
string a1=dsInBox.Tables[0].Rows[i].ItemArray[0].ToString().Trim();
string a2=dsInBox.Tables[0].Rows[i].ItemArray[1].ToString().Trim();
string a3=dsInBox.Tables[0].Rows[i].ItemArray[2].ToString().Trim();
Response.Write(a2);
}
}
}