Ø
Ø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
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