accord-net / framework

Machine learning, computer vision, statistics and general scientific computing for .NET
http://accord-framework.net
GNU Lesser General Public License v2.1
4.48k stars 1.99k forks source link

ExcelReader.GetWorksheet() throwing inexplicable error #1026

Open katycodesstuff opened 6 years ago

katycodesstuff commented 6 years ago

What would you like to submit? (put an 'x' inside the bracket that applies)

Issue description

I can't get the worksheet using ExcelReader. It was working previously (so not a file address error or something stupid) and then started throwing this error: System.Runtime.InteropServices.SEHException: 'External component has thrown an exception.'

I've tried restarting the computer to no effect, also I have looked in task manager and there appears to be no Excel file still running.

Initially it was in this form, directly copied from the 'Get started' Accord page:

        DataTable table = new ExcelReader(worksheetFileAddress).GetWorksheet("Sheet1"))

It's currently like this in an effort to correctly dispose of it (which is what I thought the issue was):

        ExcelReader excelReader = new ExcelReader(worksheetFileAddress);

        using (DataTable table = excelReader.GetWorksheet(1))
        {
            double [,] dataMatrix = table.ToMatrix();
        }

I've also tried:

ExcelReader excelReader = new ExcelReader(worksheetFileAddress);

DataTable table = excelReader.GetWorksheet(1));

Can anyone suggest a solution? Thanks. Edit: File is an .xlsx file in Excel 2016. I've installed the two Microsoft Access Database Engine 2010 for x86 and x64 system.

FireDragonGameStudio commented 6 years ago

Hy, as I ran into the same error, the following step solved it for me.

Open the excel file with Excel (2013 in my case) and resave it as .xlsx. Install the 2007 Office system driver, which can be downloaded here: https://www.microsoft.com/en-us/download/confirmation.aspx?id=23734 and ExcelReader should be able to open the file and get the worksheet.

katycodesstuff commented 6 years ago

Hi, my file was already named .xlsx. I have Excel 2016

cesarsouza commented 6 years ago

Hi @krashby,

If I am not very mistaken, a SEHException usually indicates that there was an exception in the native code (the office driver) that didn't get mapped to a .NET exception. Have you tried to force your application to be 32-bits only (i.e. by setting the platform to x86 in the project's property page), or either 64-bits only (by setting it to x64 and making sure that the "prefer 32-bits" option is disabled)?