11-11-2011 05:55 AM
Hello all!
I create a table in Word using Microsoft Word 9.0 Object Library (word2000.fp) and I have a problem with centering a table in document. I have created correctly table but I can't centered a table in my document page. I have tired all possible of ways to center a table but no results. I don't know what I'm doing wrong. Please help on the issue. Below I add a piece of my code written in Labwindows/CVI:
Word_GetProperty (docHandle, NULL, Word_DocumentApplication,
CAVT_OBJHANDLE, &appHandleL);
Word_GetProperty (appHandleL, NULL, Word_ApplicationSelection,
CAVT_OBJHANDLE, &currSelHandleL);
// adding paragraph
Word_SelectionTypeParagraph (currSelHandleL, NULL);
Word_GetProperty (currSelHandleL, NULL, Word_SelectionRange,
CAVT_OBJHANDLE, &rangeHandleL);
// creating a table
Word_GetProperty (docHandle, NULL, Word_DocumentTables, CAVT_OBJHANDLE, &tablesHandleL);
Word_TablesAdd (tablesHandleL, NULL, rangeHandleL, 5, 6,CA_VariantInt(1) ,
CA_VariantInt(0), &tableHandleL );
//Word_TableSelect (tableHandleL, NULL);
// centering a table
Word_GetProperty (currSelHandleL, NULL, Word_SelectionTables, CAVT_OBJHANDLE, &tablesHandleL);
//Word_SetProperty (tablesHandleL, NULL, Word_RowsWrapAroundText, CAVT_BOOL, FALSE);
Word_SetProperty (tablesHandleL, NULL, Word_RowsAlignment, CAVT_LONG,
WordConst_wdAlignRowCenter);
What am I doing wrong? How should be correctly it?
I greet Theodore
Solved! Go to Solution.
11-16-2011 02:46 AM
Hi Theodore85,
What is version of CVI and OS that are you using?
Also, Is it possible for you to attach your code, so that I may be able to reproduce your issue?
Thank you,
Best Regards,
ST
11-21-2011 04:53 PM
Hi Tamás Simon,
My version of CVI and OS what I'm using it's: CVI 8.5 and Windows XP Professional SP3, but ones are alright. I have found solution to my problem. The issue was lying in incorrect use of objects in the called function Word_SetProperty ( ). I used the syntax:
Word_SetProperty (tablesHandleL, NULL, Word_RowsAlignment, CAVT_LONG, WordConst_wdAlignRowCenter);
and it should be as:
Word_SetProperty (WordObjRows, NULL, Word_RowsAlignment, CAVT_LONG, WordConst_wdAlignRowCenter);
int CVICALLBACK Add_Table (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
WordObj_Columns WordObjColumns;
WordObj_Rows WordObjRows;
WordObj_ParagraphFmt WordObjParagraphsFmt;
WordObj_Paragraphs WordObjParagraphs;
WordObj_Range rangeHandleL;
WordObj_Table tableHandleL;
WordObj_Tables tablesHandleL;
WordObj_Selection currSelHandleL;
WordObj_Application appHandleL;
switch (event)
{
case EVENT_COMMIT:
Word_GetProperty (docHandle, NULL, Word_DocumentApplication,
CAVT_OBJHANDLE, &appHandleL);
Word_GetProperty (appHandleL, NULL, Word_ApplicationSelection,
CAVT_OBJHANDLE, &currSelHandleL);
// adding paragraph with centering property
Word_GetProperty (docHandle, NULL, Word_DocumentParagraphs,
CAVT_OBJHANDLE, &WordObjParagraphs);
Word_GetProperty (WordObjParagraphs, NULL, Word_SelectionParagraphFormat,
CAVT_OBJHANDLE, &WordObjParagraphsFmt);
Word_SetProperty (WordObjParagraphsFmt, NULL, Word_SelectionParagraphFormat,
CAVT_OBJHANDLE, &WordObjParagraphsFmt);
Word_SetProperty (WordObjParagraphsFmt, NULL, Word_ParagraphFmtAlignment,
CAVT_LONG, WordConst_wdAlignParagraphCenter);
Word_SelectionTypeParagraph (currSelHandleL, NULL);
Word_GetProperty (currSelHandleL, NULL, Word_SelectionRange,
CAVT_OBJHANDLE, &rangeHandleL);
// creating a table
Word_GetProperty (docHandle, NULL, Word_DocumentTables, CAVT_OBJHANDLE, &tablesHandleL);
Word_TablesAdd (tablesHandleL, NULL, rangeHandleL, 5, 6,
CA_VariantInt(1), CA_VariantInt(0), &tableHandleL);
// setting rows and columns size the table
Word_GetProperty (tableHandleL, NULL, Word_TableRows, CAVT_OBJHANDLE,
&WordObjRows);
Word_GetProperty (tableHandleL, NULL, Word_TableColumns,
CAVT_OBJHANDLE, &WordObjColumns);
Word_SetProperty (WordObjRows, NULL, Word_RowsHeight, CAVT_FLOAT, 20.5);
Word_SetProperty (WordObjColumns, NULL, Word_ColumnsPreferredWidth,
CAVT_FLOAT, 40.5);
// centering the table
Word_SetProperty (WordObjRows, NULL, Word_RowsAlignment, CAVT_LONG,
WordConst_wdAlignRowCenter);
break;
}
return 0;
}
11-22-2011 07:38 AM
Hi Theodore85,
Thank you for sharing the solution with us,
I am glad that you were able to fix the issue.
Best regards,
ST