Monday, January 8, 2018

Why does my picture appear before the text?

Leave a Comment

I am using Visual C++ to automate Word, in the following code I try to insert text followed by a picture:

// OLEParagraphs is an object of COLEParagraphs COLEParagraph LastParagraph = OLEParagraphs.get_Last(); COLERange LastParagraphRange = LastParagraph.get_Range(); COLEInlineShapes InlineShapes = LastParagraph.get_InlineShapes();  LastParagraphRange.put_Text(_T(“See picture below:”)); InlineShapes.AddPicture(strPicFileName, COleVariant(0l), COleVariant(1l), DOCX_VARIANT_OPTIONAL); 

However, after executing the code, I find the text is always put AFTER the picture, not BEFORE the picture, why?

Thanks

1 Answers

Answers 1

Given the description of the range parameter (the last for which you provide DOCX_VARIANT_OPTIONAL):

Optional Object. The location where the picture will be placed in the text. If the range isn't collapsed, the picture replaces the range; otherwise, the picture is inserted. If this argument is omitted, the picture is placed automatically. 

I would guess this is something to do with "automatic placement". Try inserting a placeholder range before the text and specifying that as the location.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment