1

I created an app that reads excel spreadsheets and performs actions on the data. I created the app using Excel 2010 and 2013. My company recently went to Office 365. Now when I run my application I get the error listed below. I assume this has something to do with Microsoft.Office.Interop.Excel but I cannot find any information on this error and how to fix it.

"Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))."

Cass
  • 537
  • 1
  • 7
  • 24

2 Answers2

0

If you do not need to control the excel application itself, you really don’t need interop. See the answers to this question or this for how to read data from xlsx sheets. There is also a neat article on codeproject, which explains OleDb.

Community
  • 1
  • 1
Nomenator
  • 1,021
  • 1
  • 13
  • 28
  • #Nomenator -- Do you have experience with these options? Which do you recommend, Linq-to_Excel or OleDbConnection? – Cass Nov 06 '16 at 22:47
  • @Cass I use Linq-to-Excel because it lets me query the excel file as if it were an entity framework data source after I have mapped the file to entities. I don’t know how much faster or slower it is behind the scenes, but the comfort of interfacing data directly with objects and using linq makes for much faster development. – Nomenator Nov 06 '16 at 22:55
  • #Nomenator -- Does Linq-to-Excel only work with .xls files do you know? I have an xlsx file and I am getting this error: "Could not load file or assembly 'LinqToExcel, Version=1.10.1.0, Culture=neutral, PublicKeyToken=9c8ea65a58f03f1f' or one of its dependencies. An attempt was made to load a program with an incorrect format." – Cass Nov 06 '16 at 23:27
  • @Cass Absolutely works with xlsx. What you're seeing there is that the assembly is not accessible. Maybe the contents of nuget package were not downloaded, maybe the dependency in your project settings is pointing to the wrong path, or maybe the libraries it uses are not installed. If you were to try loading an incompatible file, there would be a different error. This article here: http://johnatten.com/2013/09/25/c-query-excel-and-csv-files-using-linqtoexcel/ shows how to use in good detail. – Nomenator Nov 07 '16 at 04:36
  • #Nomenator -- In these examples it looks like everything is based off of column names. Have you ever done anything where you specify a range, like B8:U1023, to read the data? My app was created so the user can choose an excel doc, a specific range if necessary, and then the code will remove any unprintable characters and create a pipe delimited text file. – Cass Nov 07 '16 at 09:17
  • @Cass I never did that. The closest I can find is this answer right there: http://stackoverflow.com/q/13711280/2929539, but I do not suggest a non-tabular schema for an excel sheet. – Nomenator Nov 11 '16 at 20:10
-1

I faced the exact same exception when my computer was upgraded to Office 365. In my C# code, I was using test data stored in ".xlsx" file earlier.

I switched the excel file name to ".xls" and ran the same code that was leveraging Excel.Application and other classes from Microsoft.Office.Interop.Excel library, it worked fine.