S
sasha
Hello!
I'm struggling somewhat with inserting a picture from file in MS Word
using the type library COM interfaces.
My problem is that the picture gets inserted at the top of the document,
i.e. not obeying paragraphs, existing text, etc.
I would appreciate any and all suggestions on how to fix that. Must be
something simple I'm missing with the formatting.
I'm including the code below (hope the formatting stays put!)
TIA,
..a
BookmarksPtr bookMarks( wordApp->ActiveDocument->Bookmarks );
// add paragraph
ParagraphPtr para;
BookmarkPtr bookMark;
bookMarks->Item( TVariant( _T( "\\endofdoc" ) ), &bookMark );
WordRangePtr range( bookMark->Range );
para = wordApp->ActiveDocument->Content->Paragraphs->Add(
&TVariant( static_cast <IUnknown*>( range ) ) );
para->Range->Text = WideString( _T( "New Para" ) ).c_bstr();
para->Range->InsertParagraphAfter();
if ( bookMark ) {
InlineShapesPtr shapes = para->Range->InlineShapes;
shapes->AddPicture( WideString( picture ).c_bstr(),
TNoParam(),TNoParam(),
&TVariant( static_cast <IUnknown*>( range ) ) );
bookMark->Range->ParagraphFormat->SpaceAfter = 6;
}
//insert text
TablesPtr tables( wordApp->ActiveDocument->Tables );
if ( tables ) {
BookmarkPtr bookMark;
bookMarks->Item( TVariant( _T( "\\endofdoc" ) ), &bookMark );
WordRangePtr range( bookMark->Range );
TablePtr table( tables->Add( range, strings.size(), 1 ) );
if ( range ) {
if ( table ) {
std::list <String>::const_iterator it = strings.begin();
int row( 0 );
while ( it != strings.end() ) {
log->Lines->Add( String( it->c_str() ) );
CellPtr cell;
table->Cell( row++, 0, &cell );
if ( cell ) {
cell->Range->Text = WideString( it->c_str()
).c_bstr();
}
++it;
}
}
}
}
I'm struggling somewhat with inserting a picture from file in MS Word
using the type library COM interfaces.
My problem is that the picture gets inserted at the top of the document,
i.e. not obeying paragraphs, existing text, etc.
I would appreciate any and all suggestions on how to fix that. Must be
something simple I'm missing with the formatting.
I'm including the code below (hope the formatting stays put!)
TIA,
..a
BookmarksPtr bookMarks( wordApp->ActiveDocument->Bookmarks );
// add paragraph
ParagraphPtr para;
BookmarkPtr bookMark;
bookMarks->Item( TVariant( _T( "\\endofdoc" ) ), &bookMark );
WordRangePtr range( bookMark->Range );
para = wordApp->ActiveDocument->Content->Paragraphs->Add(
&TVariant( static_cast <IUnknown*>( range ) ) );
para->Range->Text = WideString( _T( "New Para" ) ).c_bstr();
para->Range->InsertParagraphAfter();
if ( bookMark ) {
InlineShapesPtr shapes = para->Range->InlineShapes;
shapes->AddPicture( WideString( picture ).c_bstr(),
TNoParam(),TNoParam(),
&TVariant( static_cast <IUnknown*>( range ) ) );
bookMark->Range->ParagraphFormat->SpaceAfter = 6;
}
//insert text
TablesPtr tables( wordApp->ActiveDocument->Tables );
if ( tables ) {
BookmarkPtr bookMark;
bookMarks->Item( TVariant( _T( "\\endofdoc" ) ), &bookMark );
WordRangePtr range( bookMark->Range );
TablePtr table( tables->Add( range, strings.size(), 1 ) );
if ( range ) {
if ( table ) {
std::list <String>::const_iterator it = strings.begin();
int row( 0 );
while ( it != strings.end() ) {
log->Lines->Add( String( it->c_str() ) );
CellPtr cell;
table->Cell( row++, 0, &cell );
if ( cell ) {
cell->Range->Text = WideString( it->c_str()
).c_bstr();
}
++it;
}
}
}
}