现在我有一段程序是读取excel文件 用的是OLEDB,但是在64位机器下会报一个错误。
The 'Microsoft.Jet.OLEDB.12.0' provider is not registered on the local machine.我的环境是win7(64)+VS2008+Office2007
在编译时将环境改为x86还是不行,网上说是因为64位机器不支持32位的provider。跪求解决办法。
代码片段:using System.Data.OleDb;  private DataSet readExcel(string excelpath) 
        {
            DataSet ds = null;
            try
            {
                string strconn = String.Format("Provider=Microsoft.Jet.OLEDB.12.0; Data Source={0}; Extended Properties =Excel 12.0;", excelpath);
                OleDbConnection conn = new OleDbConnection(strconn);
                conn.Open();
                string strexcel = "";
                OleDbDataAdapter mycommand = null;
                
                strexcel = "select * from [sheet1$]";
                mycommand = new OleDbDataAdapter(strexcel, strconn);
                ds = new DataSet();
                mycommand.Fill(ds, "table1");
            }
            catch (Exception e)
            {
                this.mResult.AppendText(e.Message.ToString() + "\r\n");
            }
                
            return ds;
            
        }

解决方案 »

  1.   

    机器上有没有装Office 2007?没有就要装上了。
      

  2.   

    必须要装office吗?我记得不用啊
      

  3.   

    没有你写的Microsoft.Jet.OLEDB.12.0这样的驱动存在应该是Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myExcel2007file.xlsx;Extended Properties="Excel 12.0 Xml;HDR=YES";另外把多余的空格删除
      

  4.   

     string strconn = String.Format("Provider=Microsoft.Jet.OLEDB.12.0;Data Source={0};Extended Properties=Excel 12.0 Xml;HDR=YES;", excelpath);改完之后还是不行。
      

  5.   

    你低版本的试试
    string strconn ="
    Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\";"
      

  6.   

    Office2007 是绿色版的吗 (*^__^*) 嘻嘻处理Excel我推荐使用 NPOI 自己google一下
      

  7.   

    编译不会报错吧。如果是asp.net 的话,设置应用程序池启用32位。如果是winfrom 的程序,我就不知道了。
      

  8.   

    和你是不是64位,问题应该不是很大,这里好像是说你的Excel驱动有问题
      

  9.   

    你的文件是xlsx还是xls?两者的方法不同
      

  10.   

    文件是xlsx,决定是office是正版的。公司的机子肯定是正版,肯定和64位有关系的
      

  11.   

    oledb 是基于 com 的, com 接口是指针表格, 32 位 64 位差别大了64 机器的 wow 实在是不好玩.
      

  12.   

    启用32位
    http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/b70a8fe1-4253-4043-a9c0-98b4e369821c