[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to use Excel COM interface in VC ???

Posted on 2000-05-09
4
Medium Priority
?
912 Views
Last Modified: 2013-11-20
Hi,

I have been able to get (using OLEView) the stub files for the COM
interface to Excel (XL5EN32.c and XL5EN32.h/idl)... So far so good :)

But which of the hundreds of CLSID do I use to instanciate an object?
And which objects to instanciate???

Here's what I want to do:
Open an XL sheet in a C++ application (MFC);
Read some cells;
Write to some cells;
save the sheet.

All this is simple in VB once you get a starting object...
But how to do it in VC??? Any hints? Any doc anywhere online?
I guess this code is close:
HRESULT hr;
hr = CoInitialize(0);
Application *w; // is this the right starting object???
hr = CoCreateInstance( CLSID__ExcelApplication, NULL,
        CLSCTX_INPROC_SERVER, DIID_Application, (void**) &w);

is it the right CLSID and IDD???

any hints on how to use this interface in VC will be welcomed :)

Thanks
0
Comment
Question by:aquila98
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Expert Comment

by:mandhjo
ID: 2793986
If you've already got working VB code, find the corresponding objects in the header files you have and find their corresponding CLSIDs.  The names of the classes used in VB will be the same as in the header files.

Am I missing something?
0
 
LVL 1

Accepted Solution

by:
hasmet earned 800 total points
ID: 2794378
First you #import the typelibs
#import <C:\Program Files\Microsoft Office\Office\mso9.dll>
#import <C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB>
#import <C:\Program Files\Microsoft Office\Office\excel9.olb> rename("DialogBox", "DialogBoxXL") rename("RGB", "RGB_XL") named_guids

put the correct path!!!
now

declare your Application pointer

      Excel::_ApplicationPtr m_pAppExcel;

then
forexample

      HRESULT hr;
      hr = m_pAppExcel.CreateInstance(__uuidof(Excel::Application));
            _bstr_t bstrTitle("my excel");
      m_pAppExcel->PutCaption(bstrTitle);
            Excel::_WorkbookPtr pDum = m_pAppExcel->GetWorkbooks()->Add();
m_pAppExcel->PutVisible(VARIANT_TRUE);


If you have VC++ 6, intellisense
will work just as in VBA. AND if you have VBA code, then it is almost identical to convert like this.
0
 
LVL 2

Author Comment

by:aquila98
ID: 2795922
Very nice! Thanks ;-)
That's what was missing I guess... The #inport :)

Except, I got these errors for the excel9 file:
excel9.tlh(10494) : warning C4003: not enough actual parameters for macro 'DialogBoxA'
excel9.tlh(10494) : error C2059: syntax error : ',
....

It's complaining about this DialogBoxA is there
any more rename I should do?

I am close to a solution, thanks for your help
0
 
LVL 2

Author Comment

by:aquila98
ID: 2796183
Silly me!

I remembered the rename MUST be on the same line
as the import for it to work ;-)

Thanks for your help
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question