I have developed an application which imports data into Microsoft Excel.
Am using VS2005 + .NET 2.0 and Microsoft Office 2007 is installed on my machine (Office 12).
The compiled application works fine if I run it in my machine, but when I deploy the application to other machines say those using lower versions (Office 2000), I am getting the error:
Could Not Load File or Assembly Microsoft.Office.Interop.Excel, Version 188.8.131.52
How would I then enable my application execute properly regardless of the Office (Excel) installed on the machine?
I placed the two DLLs referenced, namely Microsoft.Office.Interop.Excel.dll (Version 184.108.40.206) and Office.dll (Version 220.127.116.11) in my bin folder. I have set the properties for this reference to Copy Local = True and when I compile my application, the DLLs are copied in the debug / release folder.
Now, when I try to run the application, I already got out of the error:
“Could Not Load File or Assembly Microsoft.Office.Interop.Excel, Version 18.104.22.168”
but another error came up which is:
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Microsoft.Office.Interop.Excel.WorkbookClass.SaveAs(Object Filename, Object FileFormat, Object Password, Object WriteResPassword, Object ReadOnlyRecommended, Object CreateBackup, XlSaveAsAccessMode AccessMode, Object ConflictResolution, Object AddToMru, Object TextCodepage, Object TextVisualLayout, Object Local)
So, how do I actually create an application which would be able to export the datatable data into Excel regardless of the version of Office installed?
Look at MS Office Wrapper for .NET – it’s wrapper independent on version of Office ( testeod MS Office 97 – 2007 and works ).
In the past I have found that if you make sure all the references for Office (i.e. not the System ones) are set to copy local it will work.
I generally compile with the Office 2003 PIAs (which you can get from Microsoft’s website somewhere) and the output has worked with Office 07. I havent tried Office 2000 or XP in a long while so not sure if the output would work.
This is because it’s specifically looking for version 12 of that assembly.
In your csproj, find the reference to that assembly in your References folder. Go into Properties for that reference, and turn Specific Version to False.
You will have fewer problems – but you still might have problems – if you build against Excel 2003 instead of Excel 2007.
SpreadsheetGear for .NET is an Excel compatible library for .NET which you can deploy with your application without worrying whether your users have a particular version of Excel (it will work even if they do not have any version of Excel).
Disclaimer: I own SpreadsheetGear LLC