日期:2014-05-17  浏览次数:20981 次

C# 读取Excle数据报错,多种解决办法尝试都未能解决,急求帮助
private static DataSet ExcelToDataSet(string excelFile, params string[] excelSheets)
{
            DataSet ds = new DataSet();
            string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excelFile + ";Extended Properties=\"Excel 12.0;HDR=YES\";";         

            using (OleDbConnection conn = new OleDbConnection(strConn))
            {
                conn.Open();

                if (excelSheets == null) excelSheets = new string[1] { "Sheet1" };

                foreach (string sheet in excelSheets)
                {
                    string strExcel = string.Format("select * from [{0}$]", string.IsNullOrEmpty(sheet) ? "Sheet1" : sheet);

                    using (OleDbDataAdapter myCommand = new OleDbDataAdapter(strExcel, strConn))
                    {
                        myCommand.Fill(ds, sheet);
                    }
                }
            }
            return ds;
}


服务器环境:Windows 2003 R2 Enterprise x64 Edition Service Pack 2
开发工具:VS2010
Office:Microsoft Office Enterprise 2007
报错信息:The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.

已尝试办法一:安装AccessDatabaseEngine.exe
http://www.cnblogs.com/insus/articles/2008941.html
结果:无任何效果

已尝试办法二:IIS6.0启用32位框架
http://blog.csdn.net/playwarcraft/article/details/4835442
1.用命令启用IIS6.0 32位框架,重启IIS
2.注册.net 4.0框架,重启IIS,启用IIS扩展程序.net 4.0(32bit)
结果:程序不能正常运行

不知道是我找到的办法漏掉了一些细节还是什么问题,本以为第二种办法应该相当靠谱的。

求大神帮忙看看