OLE automation into excel sheet embedded within a word document fromC++

  • Thread starter Øyvind Sannerhaugen
  • Start date
Ø

Øyvind Sannerhaugen

Hi,

I have a Word document with an Excel sheet embedded into it. I want to
be able to manipulate the cells in this excel sheet (which is embedded
in a word document) from my Borland C++ application. I have succeeded in
getting a reference to the excel object, but only as a OLE object, and
this is not sufficient in order to manipulate the cells.

So far I have this:

TWordApplication *wordapp= new TWordApplication(NULL);
TWordDocument *worddoc= new TWordDocument(NULL);

String templateFilename = "WordDocument.doc";

wordapp->Connect();
wordapp->Documents->Open(&templateFilename);
worddoc->ConnectTo(wordapp->ActiveDocument);


InlineShapesPtr p = worddoc->get_InlineShapes();
InlineShape *shape;
p->Item((long) 0, &shape); //Quick and dirty; the document only
have one embedded excel object

WdInlineShapeType t = shape->get_Type();

if(t==wdInlineShapeEmbeddedOLEObject)
{
shape->Activate(); //At this line, the excel object is
activated, as if someone double clicked it.
String progid = (String) shape->OLEFormat->ProgID;

if(progid.Pos("Excel.Sheet"))
{
shape->OLEFormat->Object;

try
{
TExcelWorksheet *sheet = (TExcelWorksheet)
shape->OLEFormat->Object; //This one fails;

//So - What should shape->OLEFormat->Object be cast to??

//..
}
catch(...)
{
}
}
}
//....


I wonder if someone else have done something similar, and have any
suggestions? Thank you in advance to any contribution!


Best regards
 

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