views:

1499

answers:

5

Hi, 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 12.0.0.0

How would I then enable my application execute properly regardless of the Office (Excel) installed on the machine?

Thanks.

Some Updates: I placed the two DLLs referenced, namely Microsoft.Office.Interop.Excel.dll (Version 12.0.0.0) and Office.dll (Version 12.0.0.0) 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 12.0.0.0"

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?

Thanks.

A: 

I think you'll have to make different version of you application for different version of Office. Each office use a different version of the Excel interop. I think Office 2000 use the version 9... and Office 2007 the version 12.

Otherwise, you'll have to buy an Excel library do to what you want and you'll be able do deploy it on different machine.

Melursus
How would I be able to make different version when the machine I am compiling the app would only allow Office 2007 to be installed? Is there no other way for the DLL file to simply be copied on the bin folder so that when I deploy the machine, it would reference the correct DLL files?
Batuta
When you add the reference to your project, don't you have the choice of which version of Interop to use ?
Melursus
I could only reference from my machine the Interop of the current Office installed, which is in this case, Office 2007.
Batuta
Well you seems to be right. I was sure you can choose your Excel Interop version. Sorry for this misinformation ...
Melursus
A: 

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.

Coxy
I have set specific version = False and still, I am unable to run the app in machines with Office versions lower installed.
Batuta
A: 

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).

You can see samples with C# and VB source code here and download a free trial here.

Disclaimer: I own SpreadsheetGear LLC

Joe Erickson
+1  A: 

Look at MS Office Wrapper for .NET - it's wrapper independent on version of Office ( testeod MS Office 97 - 2007 and works ).

TcKs
I tried using your Office Wrapper and it works fine in Office 2007. I have not tested the same in Office 2000.One problem I am encountering is that the application create process seems to reside in memory. Even though I called MSExcel.Application.CreateApplication.Quit(), I am still prompted by a message "Do You Want To Save Changes to Book1?" when I am shutting/logging off my machine.Any further advice highly appreciated. Thanks.
Batuta
Set the property "Application.Interactive = false". Then should be all user inputs prohibited.More info about the property: http://msdn.microsoft.com/en-us/library/bb177670.aspx
TcKs
+1  A: 

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.

JDunkerley