亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

ASP.NET實(shí)現(xiàn)讀取Excel內(nèi)容并在Web上顯示

 更新時(shí)間:2014年08月20日 17:18:31   投稿:shichen2014  
這篇文章主要介紹了ASP.NET實(shí)現(xiàn)讀取Excel內(nèi)容并在Web上顯示,很實(shí)用的一個(gè)技巧,需要的朋友可以參考下

本文實(shí)例講述了ASP.NET實(shí)現(xiàn)讀取Excel內(nèi)容并在Web上顯示的方法,是非常實(shí)用的一個(gè)功能,分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

點(diǎn)擊事件代碼.cs代碼如下:

protected void Button1_Click(object sender, EventArgs e)
{
    string strPath = "d:/test.xls";
    string mystring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source = '" + strPath + "';Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";
      //"Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = '" + strPath + "';Extended Properties=Excel 8.0";
    OleDbConnection cnnxls = new OleDbConnection(mystring);
    OleDbDataAdapter myDa = new OleDbDataAdapter("select * from [Sheet1$]", cnnxls);
    DataSet myDs = new DataSet();
    myDa.Fill(myDs);
    DataGrid1.DataSource = myDs.Tables[0];
    DataGrid1.DataBind(); 
}

注意:

如果使用經(jīng)典的"Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = '" + strPath + "';Extended Properties=Excel 8.0"會(huì)報(bào)錯(cuò):外部表不是預(yù)期的格式

這是因?yàn)椋篗icrosoft.Jet.OLEDB.4.0是Microsoft Jet引擎,這適用于2003版本(2003之前的沒有測(cè)試過,所以也不知道能向下適應(yīng)到哪個(gè)版本),而在2007中,微軟對(duì)其旗下 Access 與 Excel 的主要文件格式進(jìn)行修改,并且重命名為 .accdb(Access 2007 數(shù)據(jù)庫(kù)文件)與 .xlsx(Excel 2007 文件),因此未被 Microsoft Jet 引擎所支持,不過微軟也很快的提出了 Microsoft Office 2007 Desktop Drivers: Data Connectivity Components 來(lái)支持。

因此,解決方法就是把連接字符串中的數(shù)據(jù)提供者改為 Microsoft.ACE.OLEDB.12.0即可

相關(guān)文章

最新評(píng)論