How to read an Excel file in 64bit OS using ACE OLEDB provider?

1.5k views Asked by At

I have a c# application that I have moved to a 64bit machine. This application reads in an Excel file for some data input. I would like to build this project as 64-bit. Is there any way to have my program read in this file? I find it hard to believe that there is no way to use and Excel file as input into a 64bit app. I have installed Office 2010 64 bit as well as the 2010 Office System Driver Beta: Data Connectivity Components with no luck. I'm sure that I'm just missing something really simple. My application works perfectly with 32 bit environment for .xls and .xlsx files. With 64-bit it only works with .xls and not with .xlsx. Following code is throwing exception that Specified method is not supported(when I tried to open connection with xlsx on 64-bit environment.).

Exception:

<Exception>
  <Description>An exception of type 'System.NotSupportedException' occurred and was caught.</Description>
  <DateTime>2012-10-12 17:53:53Z</DateTime>
  <ExceptionType>System.NotSupportedException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
  <Message>Specified method is not supported.</Message>
  <Source>ExcelHelper</Source>
  <HelpLink />
  <Property name="Data">System.Collections.ListDictionaryInternal</Property>
  <Property name="TargetSite">System.Data.OleDb.OleDbConnection GetConnection(System.String)</Property>
  <StackTrace>   at ExcelOperations.ExcelHelper.GetConnection(String excelFile)
   at ExcelOperations.ExcelHelper.GetExcelSheetDataSet(String excelFile, String sheetName)
   at ExcelOperations.ExcelHelper.GetXLSXDataSet(String dataFilePath, String sheetName, Int64 rowNo)
   at Intralinks.Platform.ObjectImpl.DataSource.ExcelFileSource.UpdateDataFilePath(String dataFilePath)</StackTrace>
  <additionalInfo>
    <info name="MachineName" value="NYCVMQCA007" />
    <info name="TimeStamp" value="10/12/2012 9:53:53 PM" />
    <info name="FullName" value="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
    <info name="AppDomainName" value="ILPlatform.exe" />
    <info name="ThreadIdentity" value="" />
    <info name="WindowsIdentity" value="INTRALINKS\VPatel" />
  </additionalInfo>
</Exception>
Category: Logging Exception
Priority: 1
EventId: 100
Severity: Error
Title:Enterprise Library Exception Handling
Machine: NYCVMQCA007
Application Domain: ILPlatform.exe
Process Id: 3548
Process Name: C:\IntraLinks\IntraLinks Designer\ILPlatform.exe
Win32 Thread Id: 5360
Thread Name: 

Code snippet:

    public static OleDbConnection GetConnection(string excelFile)
    {
        OleDbConnection objConn = null;
        try
        {
            // Connection String. Change the excel file to the file you
            // will search.
            String connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excelFile + ";Extended Properties=\"Excel 12.0 xml;IMEX=1\"";
            // Create connection object by using the preceding connection string.
            objConn = new OleDbConnection(connString);
            // Open connection with the database.
            objConn.Open();
        }
        catch (Exception)
        {
            try
            {
                // Connection String. Change the excel file to the file you
                // will search.
                String connString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                      "Data Source=" + excelFile + ";Extended Properties=Excel 8.0;";
                // Create connection object by using the preceding connection string.
                objConn = new OleDbConnection(connString);
                // Open connection with the database.
                objConn.Open();
            }
            catch (Exception)
            {
                throw new NotSupportedException(); 
            }
        }
        return objConn;
    }
0

There are 0 answers