【问题标题】:System.Data.OleDb.OleDbException: Could not find installable ISAMSystem.Data.OleDb.OleDbException:找不到可安装的 ISAM
【发布时间】:2012-07-19 13:47:07
【问题描述】:

我搜遍了网上,发现很多人都在问这个问题,但没有人确定我的答案。

我有一个连接类,以及一个在页面中使用该类的方法。

DataConn.cs

public static OleDbConnection ConnectExcel()
{
    //Store the connection details as a string
    string connstr =
        String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=pricelist.xlsx;Extended Properties=Excel 12.0 Xml;HDR=YES");

    //Initialise the connection to the server using the connection string.
    OleDbConnection oledbConn = new OleDbConnection(connstr);

    //Open the connection, we do this here so we can instantly be able to use SQL commands in the code.
    oledbConn.Open();

    return oledbConn;
}

public static void DisconnectExcel()
{
    _oledbConn.Dispose();
    _oledbConn.Close();
}

以及调用它的代码

protected void Page_Load(object sender, EventArgs e)
{
    // Connection String
    const string xlStr = "SELECT * FROM [Sheet2$]";

    // Create OleDbCommand object and select data from worksheet Food
    OleDbCommand cmd = new OleDbCommand(xlStr, DataConn.ConnectExcel());

    // Create new OleDbDataAdapter
    OleDbDataAdapter oleda = new OleDbDataAdapter();

    oleda.SelectCommand = cmd;

    // Create a DataSet which will hold the data extracted from the worksheet.
    DataSet ds = new DataSet();

    // Fill the DataSet from the data extracted from the worksheet.
    oleda.Fill(ds);

    // Bind the data to the GridView
    gridPricelist.DataSource = ds;
    gridPricelist.DataBind();
}

是的,我仍然得到:

System.Data.OleDb.OleDbException:找不到可安装的 ISAM。

有人可以帮忙吗?

【问题讨论】:

  • 在本题右侧的相关栏目中,您会发现数十道题与您的相同。

标签: asp.net oledb


【解决方案1】:

如果您使用超过 1 个扩展属性,则必须引用值标记,否则驱动程序无法将它们与连接字符串中的其他非扩展属性区分开来;

...Extended Properties=""Excel 8.0;IMEX=1"""

修改你的连接字符串

String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=pricelist.xlsx;Extended Properties=""Excel 12.0 Xml;HDR=YES""");

参考: Could not find installable ISAM

【讨论】:

  • 完美!感谢您的帮助。 :D
  • 1.5 年后仍在帮助
  • 无法让双引号对 web.config 中的连接字符串起作用。我改用单引号: ....MyExcelFile.xlsx;Extended Properties='Excel 12.0 Xml;HDR=YES;' " providerName="System.Data.OleDb"
【解决方案2】:

请将“扩展属性”放入''。

也就是像下面这样的语句:

字符串 connStr = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;数据源=pricelist.xlsx;扩展属性='Excel 12.0 Xml;HDR=YES'")

【讨论】:

  • 当它是 mdb (Acces) 时? :-)
【解决方案3】:

如果您安装了 LibreOffice,请查找 cli_basetypes.dll、cli_cppuhelper.dll、cli_oootypes.dll、cli_uno.dll、cli_ure.dll、cli_uretypes.dll 然后添加对您项目的引用(以使用 LibreOffice API),我也安装了“用于 Word、Excel 和 PowerPoint 文件格式的 Microsoft Office 兼容包”和“Microsoft Access Database Engine 2010 Redistributable”(无需完成 Office 安装即可获得 ACE.OLEDB.12.O 连接)。这是 VB 示例的一部分,我在其中连接到 oledb 以创建一些查询。

    OpenFileDialog.Filter = "Spreadsheets (*.xls*)|*.xls*"
    OpenFileDialog.Multiselect = False
    Try
        If (OpenFileDialog.ShowDialog() = System.Windows.Forms.DialogResult.OK) Then
            objOffice = CreateObject("com.sun.star.ServiceManager") 'preparar instancia libreOffice (prepare libreOffice instance)
            instOffice = objOffice.createInstance("com.sun.star.frame.Desktop")
            Dim obj(-1) As Object
            Dim myDoc = instOffice.loadComponentFromURL("file:///" & OpenFileDialog.FileName.Replace("\", "/"), "_default", 0, obj)
            Dim hojas = myDoc.getSheets().getElementNames() 'Obtener nombres de las hojas de calculo (get Spreadsheet names)
            System.Threading.Thread.Sleep(1000) 'Esperar a que termine la instancia Office (await libreOffice thread)
            myDoc.Close(True)

            Dim MyConnection As System.Data.OleDb.OleDbConnection 'Preparar conexión para realizar consulta tipo sql (preparing connection)
            Dim DtSet As System.Data.DataSet
            Dim MyCommand As System.Data.OleDb.OleDbDataAdapter

            If OpenFileDialog.FileName.ToUpper.Contains(".XLSX") Then
                MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & OpenFileDialog.FileName & "';Extended Properties='Excel 12.0 Xml;HDR=YES;IMEX=1;'")
            Else
                MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & OpenFileDialog.FileName & "';Extended Properties='Excel 12.0;HDR=YES;IMEX=1'")
            End If

【讨论】:

    猜你喜欢
    • 2012-08-01
    • 2015-07-17
    • 2015-10-28
    • 2012-03-18
    相关资源
    最近更新 更多