LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with ActiveX control of Word

I am using ActiveX to generate Word documents text plus graphs. The graphs are all loaded into tables to make positioning on page easier.
I based my code on the wordreport example that ships with CVI version 6 which I am using and my project includes word2000.fp and wordreport.fp from the example.
Everything is working fine with MS word v2000 but my client has MS Word 2003 and the documents produced on his PC are a mess. With Word 2003, the graphs end up in varying sizes (all same size in Word 2000) and graphs are positioned over the top of the text. Word 2003 doesn't appear to have created tables or at least the graphs (bitmaps) seem to be placed directly into the document rather than into tables.

I am guessing that the problem is due to Word 2003 having different rules for fitting content into tables and also for how it wraps text around tables.

I found some notes on MS website about wdAutoFitBehaviour and DefaultTableBehaviour which can be set to wdWord8TableBehavior. This seemed relevant but I'm not sure.

In word2000.fp I found the functions Word_TableAutoFitBehavior and Word_TablesAdd which I haven't tried yet.
Since I don't have Word 2003 on hand and I'm pretty new to ActiveX I thought it best to ask for help rather than just attack it blindly.
Am I on the right track or are there other functions in word2000.fp that I should look at?
Are there other functions that are NOT included in word2000.fp that I need and if so how do I go about implementing these additional methods?

Any help or examples much appreciated
Ewen
0 Kudos
Message 1 of 5
(4,713 Views)
Hello Ewen,

From the documentation I have found on MSDN, autofitting on tables is disabled by default in Word 2000, which might not be the case for Word 2003. So as you already suggested, you might want to explitly disable autofitting by using the TableAutoFitBehavior. The following document might be a good reference point when isolating which changes in Word 2003 is causing the incorrect behavior.

Hope that helps.
Wendy L
LabWindows/CVI Developer Newsletter
Message 2 of 5
(4,696 Views)
Thanks Wendy,

I tried using Word_TablesAdd so I could pass VARIANTs for table behaviour and autofit behaviour as follows

Word_GetProperty (docHandle, NULL, Word_DocumentApplication,CAVT_OBJHANDLE, &appHandleL);
Word_GetProperty (appHandleL, NULL, Word_ApplicationSelection,CAVT_OBJHANDLE, &currSelHandleL);
Word_GetProperty (currSelHandleL, NULL, Word_SelectionRange,CAVT_OBJHANDLE, &rangeHandleL);
Word_GetProperty (docHandle, NULL, Word_DocumentTables,CAVT_OBJHANDLE, &tablesHandleL);

tblbehav = CA_VariantInt (WordConst_wdWord8TableBehavior); // tried both of these
;tblbehav = CA_VariantInt (WordConst_wdWord9TableBehavior); // but neither helped
afbehav = CA_VariantInt (WordConst_wdAutoFitFixed); // didn't try the other 2 options for this VARIANT

// Add a table with 1 row x 3 columns
Word_TablesAdd (tablesHandleL, NULL, rangeHandleL, 1, 3, tblbehav, afbehav, &tableHandle);
WordRpt_GoToLineAfterTable (tableHandle);

// Put 1st graph into 1st cell of table
WordRpt_GoToCell (tableHandle, 1, 1);
InsertGraph (REPPANEL_GRAPH1,1);

// Put 2nd graph into 2nd cell of table
WordRpt_GoToNextCell (tableHandle);
InsertGraph (REPPANEL_GRAPH2,2);

etc.

void InsertGraph (int graphcontrol, char graphnum)
{
char imageFileName[MAX_PATHNAME_LEN];
char filename[15];
CAObjHandle imageHandle;

// Create a temporary file to hold bitmap to be loaded into report
GetProjectDir (imageFileName);
sprintf(filename, "\\rpt%d.bmp",graphnum);
strcat (imageFileName, filename);
SaveCtrlDisplayToFile (reppanel, graphcontrol, 1, -1, -1, imageFileName);
WordRpt_InsertImage (docHandle, imageFileName, &imageHandle);
CA_DiscardObjHandle (imageHandle);
Delay(0.2);
// Delete the temporary file else Windows loads the same image into all cells of table
DeleteFile (imageFileName);
}

Result: still ok for Word2000 but no better than before for Word2003

Next I tried using an existing Word doc with fixed size tables already in it (fixed row & column sizes)
and I put bookmarks in each cell and used go to bookmark and insert the bitmap
This was better but only some of the graphs ended up in the right place.
Also Word2003 produced the following error message in this case...

Error
The graphics filter was unable to convert this file
C:\Program files\...\office11\MS WORD.OLB

I read that for compatibility between word2000, 2002, 2003 you should not use OLB files and you should use late binding instead of early binding. I read that this means that instead of compiling fixed Objects, you declare variable Objects. Then when the program runs it assigns the actual type of object to that variable ??
I got real lost at this point.
Does CVI word2000 demo use early binding?
Can anyone explain how to use late binding with CVI.

Regards,
Ewen
0 Kudos
Message 3 of 5
(4,672 Views)

Hello AEDL,

The error you were receiving regarding programmatically inserting a picture in a Word document was fixed in Office XP SP3. As suggested in the following MSDN website, you might want to update to the latest MSOffice service pack to see if this resolves the error.  If so, then you should be able to avoid the issue of early/late bounding.

Thanks.

Wendy L
LabWindows/CVI Developer Newsletter
Message 4 of 5
(4,650 Views)
Thanks Wendy,
 
I actually found a solution that works with both Word2000 and Word2003 and that was to use a different function to insert the image into the table cells
 
// WordRpt_InsertImage (docHandle, imageFileName, &imageHandle);
 WordRpt_InsertImageInCell (tableHandle, imageFileName, &imageHandle);
I had already used go to cell to make sure the insertion point was in the table cell and either of the functions works for Word2000 but not for Word2003
 
I'll check out the link to MSDN anyway
 
Regards,
Ewen
0 Kudos
Message 5 of 5
(4,645 Views)