MSWORD9.OLB comaptibility with Word 2003

M

mef526

I have an application that creates a report using a Word template by
scanning the template's bookmarks and placing data at their location using
MFC DLL. Some of the data is text, some graphics. For graphics, I scale the
PNG files to fit inside of a table cell. The program works well on Word 2000
(albeit, a bug work around on the bookmark count- later).

I installed the program on a PC with Word 2003 and the reports look
terrible- the graphics don't go into the cells properly. Doesn't the
MSWORD9.OLB library work on Word 2003 machines? (Obviously not!) How much
work will it be to fix this? Is there a KB bug on MSWORD9 compatibility with
Word 2003?

About the bug I mention above, the bookmark count changes as I iterate the
loop. That is, I have to test and reset the number of items in the bookmark
collection each time through the loop, since it changes (not due to code).
Typically, the count is off by 1 after the first iteration.
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?bWVmNTI2?=,

Without seeing how your code handles the bookmarks and the graphics, it's
really difficult to make any kind of comment...

For example, how are you iterating through the bookmarks? Using For...Each or
a "normal" For? Are you allowing for the fact that bookmarks are deleted when
their content is deleted or overwritten?

What method are you using to insert the graphics? If it's AddPicture for the
SHAPES collection, that explains a lot about why you might be seeing problems.
You should be using the InlineShapes collection to put the graphic INTO a
table cell.
I have an application that creates a report using a Word template by
scanning the template's bookmarks and placing data at their location using
MFC DLL. Some of the data is text, some graphics. For graphics, I scale the
PNG files to fit inside of a table cell. The program works well on Word 2000
(albeit, a bug work around on the bookmark count- later).

I installed the program on a PC with Word 2003 and the reports look
terrible- the graphics don't go into the cells properly. Doesn't the
MSWORD9.OLB library work on Word 2003 machines? (Obviously not!) How much
work will it be to fix this? Is there a KB bug on MSWORD9 compatibility with
Word 2003?

About the bug I mention above, the bookmark count changes as I iterate the
loop. That is, I have to test and reset the number of items in the bookmark
collection each time through the loop, since it changes (not due to code).
Typically, the count is off by 1 after the first iteration.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
N

news.microsoft.com

Thanks for your reply.
Without seeing how your code handles the bookmarks and the graphics, it's
really difficult to make any kind of comment...

Here's some code from the DLL that is in question:

// ----------------------------------------------------------------
// Loop Through all the bookmarks in the template
int nBkMrkCnt = oBookmarks.get_Count();
for (int nBkMrkNum = 1; nBkMrkNum <= nBkMrkCnt; nBkMrkNum++) {

// ------------------------------------------------------------
// Go to the bookmark
oView.put_SeekView(wdSeekPrimaryHeader); //NOT USED IN GRAPHICS
oBkmrk.Select();

// ------------------------------------------------------------
// Type the text at the selection point
char acVal[128];
char *pcMyVal = NULL;

if (eVppType & eVppType_FLAG_GRAPHICFILE) {
// The bookmark is a graphic
pcMyVal = (char*)pzMap->pAddr;
if ((NULL == pcMyVal) || (0 == *pcMyVal)) {
continue; // No File spec'd
} else if (_access(pcMyVal, 0) != 0) {
cstrMsgGraphic = cstrMsgGraphic + " \"" + pcMyVal + "\"";
nErrGraphic++;
continue; // File not found
}
CWordRange oRange = oBkmrk.get_Range();
oInlineShape = oInlineShapeColl.AddPicture(pcMyVal, vFalse, vTrue,
vOpt);

/// Send image to back in case we need to put text on top of it
CWordShape oShape = oInlineShape.ConvertToShape();
oShape.ZOrder(1); // Send to back

// Scale the image to fit in the Cell and center it
CWordWrapFormat oWrapFormat = oShape.get_WrapFormat();
CWordCellsColl oCellsColl = oRange.get_Cells();

int nCellCnt = oCellsColl.get_Count();
if (nCellCnt == 1) {
oShape.put_LockAspectRatio(0);
CWordCell oCell = oCellsColl.Item(1);
float fCellWidth = oCell.get_Width();
oShape.put_Width(fCellWidth * min(1.0F, fBitMapScale));
float fShapeWidth = oShape.get_Width();
oShape.put_Left((fCellWidth - fShapeWidth) / 2.0F);
float fShapeHeight = oShape.get_Height();
if (oCell.get_HeightRule() == wdRowHeightAuto) {
fBitMapScale = min(fBitMapScale, 1.0F);
oShape.put_Height(fShapeHeight * fBitMapScale);
oShape.put_Top(((1.0F - fBitMapScale) * fShapeHeight) / 2.0F );
} else {
float fCellHeight = oCell.get_Height();
oShape.put_Height(fCellHeight * fBitMapScale);
oShape.put_Top((fCellHeight - fShapeHeight) / 2.0F);
}

} // if (eVppType & eVppType_FLAG_GRAPHICFILE)

// A bug in MS Word can cause the number of bookmarks in the word template
to change as they are itterated
int nBkMrkCnt_2 = oBookmarks.get_Count();
if (nBkMrkCnt_2 != nBkMrkCnt) {
--nBkMrkNum;
nBkMrkCnt = nBkMrkCnt_2;
}
} // for (int nBkMrkNum = 1; nBkMrkNum <= nBkMrkCnt; nBkMrkNum++) {
 
C

Cindy M -WordMVP-

Hi News.microsoft.com,

OK, I hope I can interpret your code correctly... :)
// A bug in MS Word can cause the number of bookmarks in the word template
to change as they are itterated
I think this comes from how you're iterating through the
collection. If any actions you take affect the number of bookmark
(add or delete), then "of course" there will be more or less than
you started with. In cases where looping through a collection
could actually modify the members of the collection, it's better
to loop through from the END to the start. Roughly (and I'm just
guessing at the proper syntax, here):
for (int nBkMrkNum = nBkMrkCnt; nBkMrkNum >0; nBkMrkNum -= 1)
/// Send image to back in case we need to put text on top of it
CWordShape oShape = oInlineShape.ConvertToShape();
This is certainly where the problem is coming from; Word 2003, as
I recall, handles Shapes around table cells slightly differently
than Word 2000 did. So when you're converting to a Shape, the
graphic is positioning itself in a place you don't expect.

My suggestion would be that you sit down with Word 2003 and go
through the actions of inserting a graphic into a table cell,
resizing it, then applying the text wrap formatting manually and
watch what it does. That may give you some clues as to how your
code will need to be modified.
Doesn't the
MSWORD9.OLB library work on Word 2003 machines?
It is working (otherwise your code wouldn't function at all).
What's happened is that some change in how a later
version of Word handles graphics - in relation to tables - is
causing unexpected results. My best guess is that it has
something to do with Word 2002 and later supporting text wrap
formatting around graphics WITHIN table cells, something earlier
versions couldn't do...

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8
2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 

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