LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Finding Specific Table in MS Word

Hi All,

 

As part of my project i need to design vi which uses ActiveX controls to read my table which is present in my MS Word document. The read table is displayed in my front panel. The program is designed from solutions obtained in this discussion forum. As part of the program if there are multiple tables i am able to read only last table. Instead i want to read table specificed by user or specified in program. And i could not find solution for this. I also tried reading table using table of contents which seems to unsuccessful again. Could anyone help me on this. I need simple solution that is if i have multiple table then specific table should be read from the document. Attached my vi for your refrence.

 

Thanks in advance

0 Kudos
Message 1 of 16
(5,306 Views)
Did you check this post where using tables property gives the reference and by selecting proper index you should be able to get : http://forums.ni.com/t5/LabVIEW/Reading-Tables-in-MS-WORD-using-LabView-amp-ActiveX/m-p/712537/highl...
Thanks
uday
0 Kudos
Message 2 of 16
(5,298 Views)

Interesting problem.  Can you also generate a sample Word document with text and, say, three tables so that we have something to use as "data"?  I have some ideas, but since I rarely use Word anymore for writing documents, and since it is your document, prepared with your version of Word (which version of Word are you using?), getting a sample from you seems like the better idea.

 

Bob Schor

0 Kudos
Message 3 of 16
(5,296 Views)

Hi Uday,

 

Yes i did check the post. But i did not feel that could be the solution so asked this doubt.

 

Hi Bob,

 

Please find attached document with 3 tables. Version of MS word i am using is 2010. Please do check and let me know.

 

0 Kudos
Message 4 of 16
(5,260 Views)

Did you try changing the value to Tables->index property by numeric value instead of tables count?

Thanks
uday
0 Kudos
Message 5 of 16
(5,253 Views)

OK, first, some General Comments.  NI provided "hooks" into Word and Excel for the purpose of producing reports, i.e. writing Word and Excel documents, giving little thought to reading either type of Document.  They did "bend" a bit on Excel, having Excel Get Data to allow you to read a cell, but didn't provide the same for Word.

 

There is, of course, ActiveX, quirky and difficult.  After playing around a bit, I found what might be the problem you are having -- unlike almost every other "indexing" counter that starts with 0, the counters for Table, Row, and Column appear to start with 1.  Specifically, if I look at your tables for a unique identifier, the first Table has U10M in Row 3 of Column 2 (here I'm using "human-counting, origin 1" numbering).  So here is some code that opens this Word Document using the RGT, gets the number of Tables (3, correct), gets an ActiveX reference to the Tables, then proceeds (much as you did) to retrieve the text U10M.  To do so, I put "1" (not 0!) in the Tables Index, 3 in Row, and 2 in Column.  I'm attaching my code as a Snippet -- if you don't have LabVIEW 2016, you should still be able to follow this and, more importantly, "repair" your own code now that you "know the trick" (to start with 1, not 0).

Word Table.png

Bob Schor

0 Kudos
Message 6 of 16
(5,248 Views)

There is a more direct (and less intuitive) way of getting table data using the Table Convert To Text method followed by Spreadsheet String To Array.vi.

 

Word Get Table.png

Message 7 of 16
(5,230 Views)

Hi All,

 

Solution 1(Bob_Schor): this is not what i was looking for but i think this could help me in future. Thank you.

 

Solution 2(ben64): I had already tried this solution before. But if i give index through control or constant i usually get some error with error code -2147023170(The remote procedure call failed. in MS_Word.vi). And if my code is running continously i obtain error alternatively that is table gets upated once and then error, and this is happening untill i stop(I am using LabVIEW version 2014). Could you please let me know the solution for this?

 

Error.jpg

 

Regards,

Pragathi

0 Kudos
Message 8 of 16
(5,216 Views)
When I ran your code by giving the indices 1,2,3 respective table data appeared in table.
- I am curious what could have gone wrong.
- can you post your block diagram snippet?
Thanks
uday
0 Kudos
Message 9 of 16
(5,212 Views)

Hi Uday,

 

Even i am getting data in table If i run the code but for every alternate run of code i am getting this error and my table is getting emptied when error occurs. Please find attached code.

 

Regards,

Pragathi

0 Kudos
Message 10 of 16
(5,209 Views)