1

I need to use Excel if it is installed on the target machine, or produce a text file if it is not.

I check for the presence of the excel application registry key, but before I can do that, I get a

System.IO.FileNotFoundException: Could not load file or assembly Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral,PublicKeyToken=71e9bce111e9429c

or one of its dependencies.

How can I detect if an interop assembly is available and prevent the run-time trying to load it if it isn't. (I don't know what version of Excel may exist on the target, so I don't think I can redistribute an interop in case its the wrong one.)

Raghu Srikanth Reddy
  • 2,703
  • 33
  • 29
  • 42
  • I think this may help http://stackoverflow.com/questions/3266675/how-to-detect-installed-version-of-ms-office/3267832#3267832 – ígor May 30 '13 at 09:08
  • Have you added a reference to the Interop assembly to your object? Does the error appear before the application even starts or does it appear in a specific line of code? – Panagiotis Kanavos May 30 '13 at 09:58

1 Answers1

2

It seems that you added a reference to a specific interop assembly in your code. Your application will not even load since it can't find all the assemblies it needs to run. If you absolutely have to use Excel through Interop, you will have to remove the reference and load the assembly dynamically with Assembly.Load.

You don't need Excel at all if all you want is to read/create an Excel file.

XLSX is just a bunch of zipped XML files. The OpenXML SDK by Microsoft allows you to manipulate the files withoud dealing with the XML directly and there are other libraries that sit on top of the SDK to make programming even easier.

Generating Excel 2010 Workbooks by using the Open XML SDK 2.0 offers a pretty detailed explanation of the XLSX format and how you can use the SDK to create simple and complex spreadsheets easily.

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
  • Ah, legacy, legacy - I nbeed to maipilate exisitng xls files as well as xlxs files. –  May 30 '13 at 14:56
  • I plan to use Assembly.load, and catch the exceptions, but do you know where I can find the long name for the assemblies for Excel 2012 and 2010? –  May 30 '13 at 15:32