Batuta
Batuta

Reputation: 1714

.NET Office interop using version independent office

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.

Upvotes: 3

Views: 5941

Answers (4)

JDunkerley
JDunkerley

Reputation: 12505

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.

Upvotes: 1

TcKs
TcKs

Reputation: 26642

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

Upvotes: 2

Joe Erickson
Joe Erickson

Reputation: 7227

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

Upvotes: 0

Coxy
Coxy

Reputation: 8927

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.

Upvotes: 0

Related Questions