MS Excel with C#

  • Thread starter Thread starter Yakimo
  • Start date Start date
Y

Yakimo

I developed an application in C# using MS Excel objects. The app works fine
on the computers with Excel 2000 installed, but gives an error on computers
with Excel 2002.
I checked an found out that my app cannot compile on PC with Excel 2002
because Microsoft has changed the numbers of parameters in some functions.
For example Workbooks.Open has 13 arguments with EXCEL 2000
Excel 2000 (13 arguments)
wb =
m_Excel.Workbooks.Open(Path.Combine(System.IO.Directory.GetCurrentDirectory(
), "myfile.xls"),
optParam,optParam,optParam,
optParam,optParam,optParam,
optParam,optParam,optParam,
optParam,optParam,optParam);
but the same function with Excel 2002 has 15 arguments, so the compilation
failed.

How can I build my application, so it will work with both Excel 200 and 2002
?
Of course I can have 2 versions (with conditional compilation) but it seems
for me not the best aproach.
Any ideas?

Regards,
Yakimo
 
I would have wrapper classes that implement the things you actually need to
do. For example you probably don't care about all 15 of those Open()
arguments, so you could have a method that takes the 3 or 4 you really care
about.

The wrapper instance would be intialized for a particular Excel version and
then internally would make the correct calls to the Excel Automation
objects.

The only problem with this is that the wrapper class would either have to
bind at runtime to the proper Interop assembly, or you would have to
distribute all possible Interop assemblies with it.

--Bob
 
Back
Top