LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read a value of a table cell of a table created in word?

Hello,
 
I've created several tables in word and would like to retrieve values from one table to use in calculations in another table. I know how to get to the cell that has the values I need but the report instrument only has write to cell functions no read functions.
 
Thanks in advance
Mike
0 Kudos
Message 1 of 3
(3,142 Views)

Hello,

You can try to use the procedure:

/********************************************************************************/

int WORDTABLE_ReadFromCell(CAObjHandle tableHandle, int numRow,  int numCol, char text[])       
{
    CAObjHandle      appHandleL = 0;
    CAObjHandle      currSelHandleL = 0;
    WordObj_Cell     cellHandleL;
    WordObj_Rows  rowsHandle;
    WordObj_Cell     cell;
    HRESULT           error = S_OK;     
    char                     *ptr=NULL;
 
    errChk (Word_TableCell (tableHandle, NULL, numRow,numCol, &cellHandleL));
    errChk (Word_CellSelect (cellHandleL, NULL));
    errChk (Word_GetProperty (tableHandle, NULL,  Word_TableApplication,CAVT_OBJHANDLE, &appHandleL));
    errChk (Word_GetProperty (appHandleL, NULL, Word_ApplicationSelection, CAVT_OBJHANDLE, &currSelHandleL));
    errChk (Word_GetProperty (currSelHandleL,  NULL, Word_RangeText, CAVT_CSTRING, &ptr));
    strcpy(text,ptr);
    text[strlen(text)-2] = '\0';
    CA_FreeMemory(ptr);
    ptr = NULL;

Error:
    CA_DiscardObjHandle(currSelHandleL);       
    CA_DiscardObjHandle(appHandleL);       
 
    return error;
}
/***********************************************************************************************/

Best regards,

Janusz

Message 2 of 3
(3,109 Views)

Janusz,

Thank you!

That worked perfectly!

Mike

0 Kudos
Message 3 of 3
(3,065 Views)