Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting Row & Column data from MS-Word document QTP+
#1
Solved: 11 Years, 3 Months, 3 Weeks ago
Hi,

I have a input test data in MS-Word document as Row/Column format.

I would like to fetch that data from Script, store it in veriable and want to use it in Test.

Script:
Code:
Set objWord = CreateObject("Word.Application")
Set word_doc = objWord.documents.Open("C:\1_word.doc")

' i can get the parameter count by
Code:
para_count = word_doc.Paragraphs.count
msgbox para_count

Query:
But how do i get the Row and Column data separately (like for Excel sheet, we can easily fetch that by "ColumnName" & 'SheetID')

--> Can it be possible to fetch Row/Column data for MS-Word document like Excel document?

--> Please guide and if possible pls give the code.

Thanks in advance
Shrinivas
Reply
#2
Solved: 11 Years, 3 Months, 3 Weeks ago
Yes, this is possible to get data from table in Word doc.
Try this
Code:
objWord.Selection.Tables(1).Cell(1,1).Select
msgbox objWord.Selection.Text

here 1 in Tables(1) depends on number of table in the word an from which you want to fetch data
Cell(1,1) - can vary on row and column you want.

Hope this will help you.

Reply
#3
Solved: 11 Years, 3 Months, 3 Weeks ago
Hi Saket,

gr8, thanks for your help, its really good.


Only one small query:

If i want to count number of Row available in Table(1), Column 2 i.e Cell(1,2). Can i use GetRowCount() method to get that, like i tried following:

Code:
m_total = objWord.Selection.Tables(1).Cell(1,2).GetRowCount()
msgbox m_total

But its not working. Do we have any other method to get no. of rows present in Column 2.

Thanks
Shrinivas
Reply
#4
Solved: 11 Years, 3 Months, 3 Weeks ago
You can not use GetRowcount which is a QTP native method and will not work with word table.
Code:
objWord.Selection.Tables(1).Rows.Count
will give you the row count for the table

Reply
#5
Solved: 11 Years, 3 Months, 3 Weeks ago
Hi,

And with the code:

Code:
objWord.Selection.Tables(1).Cell(1,2).Select
msgbox objWord.Selection.Text

The message box is showing Extra Square, below actual value. Please check the attachment for ex.

Can it be possible to remove that extra Square.

Also tried following code:
Code:
m_total = objWord.Selection.Tables(1).range
msgbox m_total

And with that for each value from both columns showing extra Square (as shown in attachment) below the value.


Can it be possible to remove that extra square? and if so how...

Please guide.

Thanks
Shrinivas


Attached Files Image(s)
   
Reply
#6
Solved: 11 Years, 3 Months, 3 Weeks ago
I think that is carriage return characters and this occurs due to the whole cell is selected.
You can use 'Replace' Function to remove them.

Reply
#7
Solved: 11 Years, 3 Months, 3 Weeks ago
Nope 'Replace' function not working. Because small square is not existing as separate value.

Do it have any concerns with Word document settings. Also tried with Autofit options but no use.

Thanks
Shrinivas
Reply
#8
Solved: 11 Years, 3 Months, 3 Weeks ago
How did you used the Replace function?
try replacing with Chr(13) or Chr(7) or both
This should work. Let me know if any issue

Reply
#9
Solved: 11 Years, 3 Months, 3 Weeks ago
Did a small mistake while using Replace.

But now it is working absolutely fine.

Thanks a lot....Saket

Have a nice day
Bye
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Check the word and get no. of times that word in the webpage Sandeep.san229 0 1,438 10-31-2018, 06:42 PM
Last Post: Sandeep.san229
  pageDown in word.application wannel 0 1,755 11-25-2016, 10:06 PM
Last Post: wannel
  Searching for and selecting row in Datawindow zsl0009 0 2,800 08-04-2015, 01:02 AM
Last Post: zsl0009
  QTP is not identifying table with column names property but its identifing with index Anuradha B 1 2,999 02-12-2015, 04:00 PM
Last Post: Kirill
  Automating Word Docs bart02 0 2,786 07-18-2014, 03:25 AM
Last Post: bart02

Forum Jump:


Users browsing this thread: 2 Guest(s)