CSDN博客

img ghjhot

读取excel

发表于2004/9/28 9:44:00  963人阅读

分类: 我的.net

命名空间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);
    }
   }
  }

阅读全文
0 0

相关文章推荐

img
取 消
img