LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Centering a table in Word LabWindows

Solved!
Go to solution

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

    

0 Kudos
Message 1 of 4
(3,374 Views)

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

Best Regards,
T Simon
National Instruments
Applications Engineer
Certified LabVIEW Developer - Certified TestStand Architect
0 Kudos
Message 2 of 4
(3,342 Views)
Solution
Accepted by topic author Theodore85

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);

 

The entrie code source to create a table with centering should look like this:
 

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;
}

 

I added also some table properties, such as size rows and columns, paragraph with centering. I hope that it will be useful to someone.
         I would like to thank you for your help and wish you all the best:)
         Theodore85
0 Kudos
Message 3 of 4
(3,320 Views)

Hi Theodore85,

 

Thank you for sharing the solution with us,

I am glad that you were able to fix the issue.

 

Best regards,

ST

Best Regards,
T Simon
National Instruments
Applications Engineer
Certified LabVIEW Developer - Certified TestStand Architect
0 Kudos
Message 4 of 4
(3,311 Views)