C++ and Office (Excel) development

C

cim

Hello everyone,
I would like to be able to write generic (i.e. non-managed) C++ code which I
could use in a library with Excel as the front end. I would like to be able
to maintain a code base that will compile in a non-windows environment. Can
anybody provide any pointers on how to do that? Can anybody provide any clues
as to how that code can be wrapped for use with Excel? Or is COM (or managed
code) the only way to go?

Thanks in advance,
Constantinos
 
G

Giovanni Dicanio

I would like to be able to write generic (i.e. non-managed) C++ code which
I
could use in a library with Excel as the front end. I would like to be
able
to maintain a code base that will compile in a non-windows environment.

For the non-windows environments, you can use multiplatform and standard
libraries, like STL.
For example, if you want to store an array of data, you have several
options: you could use CAtlArray (from ATL), but it is Windows-specific.
Another option is to use std::vector from STL, which will compile fine also
on non-Windows platforms.

You can design your code separating the multiplatform part (written in
standard C++, using standard and multiplatform libraries like STL), from the
Windows-specific part.
The Windows-specific part should use COM to export the multiplatform "core"
part towards Excel.
Excel (and Office in general) are heavy based on COM technology, so I think
that COM is the way to go if you want to extend Excel from native C++.

A possible architecture could be like the following:

- core part (standard C++, STL)
- COM objects wrapping the "core" (built with C++ with ATL)
- VBA code in Excel that calls the COM objects

There is also another option to built Excel add-ins, using XLL technique
that does not require COM.
It is explained a bit here:

http://support.microsoft.com/kb/178474

However, I think that it is a legacy technology, and I would definitely
suggest using COM for that job.

Giovanni
 
C

cim

Thanks for the answer Giovanni.

The problem I have is with the design and implementation of the wrappers.
First of all every single class would have to be wraopped. Second, what
happens with inheritance? Do you wrap both the parent and the child for a
class? And how about virtual methods for these classes? It seems to me that
this becomes a mess fast.

C.
 
G

Giovanni Dicanio

cim said:
Thanks for the answer Giovanni.

You are welcome.
The problem I have is with the design and implementation of the wrappers.
First of all every single class would have to be wraopped. Second, what
happens with inheritance? Do you wrap both the parent and the child for a
class? And how about virtual methods for these classes?

You can have a system made up by several objects (classes), but it can
happen than only a small subset of them needs to be exposed to Excel via COM
(the other classes are part of the core system, but they are not required to
be exposed in the interface part).
So you can just build COM objects to wrap this subset.

I don't know other options different than COM to expose an object model
using native code and C++ (if we exclude the primitive XLL technique I
posted in the other message).

Giovanni
 
J

James Simpson

The easiest/cheapest way to do this is to save the file as a CSV file,
separating
each field with commas.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top