zoukankan      html  css  js  c++  java
  • asp.net采用OLEDB方式导入Excel数据时提示:未在本地计算机上注册"Microsoft.Jet.OLEDB.4.0" 提供程序"

     笔者在项目中做做了一个从Excel表格中导入数据的模块、大体上asp.net项目中导入Excel大体分成三类:

    1)采用c#内置方案System.Data.OleDb(限制较小, 通用)

    2)采用Excel的COM组件(会有版本问题)

    3)采用伪Excel文件、即使用文本流的方式根据需求自己定义数据格式。同时在服务端进行反格式化

    笔者采用的是方案一、相关联开发环境如下:

    Windows 7(x64)

    Visual Studio 2010

    方案中使用的代码:

    复制代码
    public sealed class ExcelHelper
    { private const string CONNECTION_STRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Excel 8.0;"; public static DataSet ExcelDataSource(string filePath, string sheetName) { OleDbDataAdapter oada = new OleDbDataAdapter("select * from [" + sheetName + "$]", string.Format(CONNECTION_STRING,filePath)); DataSet ds = new DataSet(); oada.Fill(ds); return ds; } public static List<string> ExcelSheetName(string filePath) { List<string> list = new List<string>(); OleDbConnection conn = new OleDbConnection(string.Format(CONNECTION_STRING, filePath)); conn.Open(); DataTable sheetNames = conn.GetOleDbSchemaTable (System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" }); conn.Close(); foreach (DataRow dr in sheetNames.Rows) { list.Add((string)dr[2]); } return list; }
    复制代码

    程序在执行时会抛出:

    异常详细信息: System.InvalidOperationException: 未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序。

    分析原因:

    用于 Access 和 Excel 数据库的 Microsoft OLE DB Provider for Jet 在 64 位版本中不可用。

    最终解决办法:

    在IIS中启用32位应该程序、设置见图。

  • 相关阅读:
    基于NodeJS的全栈式开发
    Android 反编译apk 详解
    AngularJS 中文资料+工具+库+Demo 大搜集
    Mongodb集群搭建的三种方式
    Ubuntu下解决bash 没有那个文件或目录的方法
    ubuntu12.04 安装配置jdk1.7
    CentOS怎样查看系统信息
    Ubuntu 安装 Redis
    Redis快速入门
    js去掉双引号
  • 原文地址:https://www.cnblogs.com/51net/p/3917419.html
Copyright © 2011-2022 走看看