Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Application platform problem

Status
Not open for further replies.

zackiv31

Programmer
May 25, 2006
148
0
0
US
I've developed an application (that creates excel files) on my Vista box with Office 2007 on it.

It runs perfectly well. When I move the App to another box (XP) with Office 2003 on it, and try to run it.. It tries to load Office 12.0 dll, which doesn't exist...

How can I change my application to compile for all versions of excel? (or is it not possible?)

btw. the two References I've added to my Project are:
Microsoft.Office.Interop.Excel;
Microsoft.Office.Core;
 
you need to include a reference to all versions of the dll. I'm not sure if/how this is possible, but it's worth a shot.

the thing is you may need alias the namespaces/objects for both xp and 07 assmeblies in the code. This will also require if/else statements to determine which objects to use. This is a valid option if you only call the excel code within 1 class or a hand full of functions.

If, however, there is excel references scattered throughout your code, then a better approach would be to create a common interface and have 07 and xp adapters. which inherit the common interface. use a factory object to determine which concrete object to use.

Again this is all dependent on referencing 2 versions of the same assembly. I have a feeling VS doesn't like this, but i could be wrong.

a 3rd option would be to create a plug-in framework that would dynamically load the assembly on startup. This is the most complex solution and will still require a common interface designed by you to account for the differences between versions.

I'm sure your not the first person to encounter this problem. Have you googled how other are handling the problem.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
One option is to set your reference the earliest version of Excel that your users are likely to have. Early binding using a reference will usually cope with a PC having a later version of Excel than your code originally referenced, but as you have found it wont cope so well when the version of Excel on the PC executing the code is older than the version you originally referenced.

Another option may be to use late binding to Excel, removing the need for the reference to be set in advance.
 
Well I have compiled my code on a machine with 2003, and it indeed does run on a machine with office 2007...

My question is how can I change the references in the solution explorer to reference older versions? I would love to be able to have it reference office11 (2003) but be able to compile it on my box that has 2007 on it.

Details on how to do this or instructions how to do late (runtime?) loading appreciated.
 
Wow... late binding sucks...

No Intellisense, and the complexity it takes to perform simple manipulations is unbelievable...

So it either takes a lot more code or more version controlled users...


thanks for the link craig
 
It's not that hard to late bind.

Perhaps you could develop using early binding then convert to late binding? Maybe there is a plugin which does the conversion? If not, why not write one? It can't be that hard?

C
 
BTW, VB.Net is better at this in terms of code.

Example of the differences.....

C#

try
{
Type t = Type.GetTypeFromProgID( "Word.Application" );
object w = Activator.CreateInstance( t );

// w.Visible = true
t.InvokeMember( "Visible", BindingFlags.SetProperty,
null, w, new Object[] { true } );

// w.Documents...
object docs = t.InvokeMember( "Documents", BindingFlags.GetProperty,
null, w, null );
// ...Add
t.InvokeMember( "Add", BindingFlags.InvokeMethod,
null, docs, null );

w = null;
}
catch( TypeLoadException ex )
{
...
}


VB.Net

dim o as object
o = CreateObject( "Word.Application" )
o.Visible = True
o.Documents.Add
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top