Open an Excel 2003 spreadsheet with C#. Could not find installable ISAM. Exception

后端 未结 4 1395
臣服心动
臣服心动 2020-12-20 16:27

I need to pull data from an xls, I also need have the user be able to change the location of the file it will. So an OleDbConnection seemed like a good start, and it was unt

相关标签:
4条回答
  • 2020-12-20 17:04

    I think it's just because you have to enclose the Extended Properties in quotes if you have more than one

    OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\test.xls;
    Extended Properties='Excel 8.0;HDR=Yes;IMEX=1';");
    

    Or if single quotes don't work (you get the idea)

    OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\test.xls;
    Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1;"";");
    

    While your example doesn't show it, this error can also be caused by spaces in the file path. In which case you would need to wrap the file path in quotes as well.

    OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""F:\test.xls"";...
    
    0 讨论(0)
  • 2020-12-20 17:08

    Assuming your system requirements include an installation of Excel, you can use the Excel Object Library

    Excel.Sheets sheets = m_Excel.Worksheets;
    Excel.Worksheet worksheet = (Excel.Worksheet)sheets.get_Item(1);
    Excel.Range range = worksheet.get_Range("A1", "E1".ToString());
    

    etc.

    See also VSTO

    0 讨论(0)
  • 2020-12-20 17:27

    SpreadsheetGear for .NET is a royalty free spreadsheet component for .NET and should do everything you want for 32 bit and 64 bit .NET with no dependency on Excel (or anything else other than .NET 2.0+).

    You can see live ASP.NET samples here and download the free trial here if you want to try it yourself.

    Disclaimer: I own SpreadsheetGear LLC

    0 讨论(0)
  • 2020-12-20 17:30

    Try this

    I had this problem. just because of quotes

    string sConnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + sFilePath + ";" + "Extended Properties='Excel 8.0;HDR=YES;'";
    
    0 讨论(0)
提交回复
热议问题