View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
danAutodesk danAutodesk is offline
external usenet poster
 
Posts: 3
Default excel 2003 and c++ API documentation?

Thanks for your pointer. Alas it turns out at least a few of these articles
are the same ones I was able to Google. I can't get past the application
initialization. As such, I have a few more questions. I appologize in
advance for the length of this message (brevity is scarce in code
descriptions! ;-).

---
1. When I add any Excel object through the class / type lib wizard, a
header is generated for the selected object. That part works fine. At the
top of each header is the following code:
#import "C:\\Program Files\\Microsoft Office\\OFFICE11\\EXCEL.EXE"
no_namespace

When I #include this header in my project, the compiler doesn't like the
#import; warns of duplicate macro definitions and automatic exclusions. More
importantly, the compiler throws errors becasue of redefinitions in the
generated excel.tlh file.

---

2. Some imported Excel objects (such as, but definitely not limited to
Workbooks.h) that contain method signatures suchs as the ones below:
Application get_Application()
{
Application result;
...
XlCreator get_Creator()

These method signatures can't possibly work since the return types don't
exist. It's easy enough to fix these signatures so things compile.
Moreover, the code *seems* to run, but I don't know what is going on under
the covers at all.

---

There are several other issues like these that make me wonder whether I'm
dealing with bugs, or whether c++ developers are just supposed to get through
this with Excel.

I understand c++ developers are a little more wiling to endure difficulty.
That's why I was hoping there was some documentation on these APIs. Bumping
around in the dark is a losing proposition.

Finally, all the examples posted on the side you referenced look like they
were made with older versions of Excel. The object signatures are no longer
relevant. For example one example indicates: oBook =
oBooks.Add(covOptional); but the signature for this method in the generated
class (Excel 2003) is: (Add)(LPCTSTR Name, VARIANT& iDataType, Parameter * *
RHS)

There are no optional parameters apparently, and with no documentation on
type values, Parameter or the RHS macro, it's very difficult to know where to
go from here.

Again, I apologize for the length of this post. If you've gotten this far,
I thank you very much, and thank you even more for any and all assistance you
can provide.

dan

"Tom Ogilvy" wrote:

go to
http://support.microsoft.com

go to advanced search and search on C++ and Excel

--
Regards,
Tom Ogilvy


"danAutodesk" wrote:

I have been looking for documentation - any documentation or better yet, real
code examples regarding the c++ objects and methods for excel 2003. My
progress has been based on reverse engineering and guessing so is quite slow.
Help!

My purpose is exceptionally simple, to read (only, not write or format) data
from excel workbooks/worksheets.

I have a c++ MFC DLL project and have created excel classes from the type
library (actually .../EXCEL.EXE). The trouble really starts there - the
imported classes won't compile without some hand editing (Is that expected?).

After some "fixing," I can start the app with the following code:
if(!app.CreateDispatch(L"Excel.Application"))
{
//...todo - add error handling and cleanup
return;
}
else
{
//Make the app visible and verify the name - just for kicks!
COleVariant covOptional(DISP_E_PARAMNOTFOUND,VT_ERROR);
app.put_Visible(TRUE);
app.put_UserControl(TRUE);
CString appName = app.get_Name();
...
}

But that's where I'm stuck. I can't open an existing workbook because I
don't know what to supply for the workbook methods to open an existing
workbook. Brining up any of the dialogs (such as app._FindFile()) control is
transferred to the app (away from my DLL) and is not returned until I dismiss
the dialog manually. Needless to say, that's definitely not useful....

Here's the code I'm currently playing with:

COleVariant covOptional(DISP_E_PARAMNOTFOUND,VT_ERROR);
ExcelWorkbooks excelWBs = app.get_Workbooks();
ExcelWorkbook excelWB;
appName = app.get__Default();
ExcelParameter excelParam = excelWBs.get__Default(COleVariant((short)2));
excelWBs.Add(_T(".\\ExcelExample.xls"),covOptional , (ExcelParameter
**)&excelParam);


I've gotten this far by reverse engineering and poking around on Google --
VERY FRUSTRATING to spend several hours to get 10 lines of code for something
so trivially simple.

The VB and C# examples are plentiful and I can make those work easily. But
for many reasons this has to be a C++ project.

If could point me to any c++ code examples or documentation I would be
greatly relieved! ;-)

Thanks in advance.

dan