Micro Focus QTP (UFT) Forums
Getting Row & Column data from MS-Word document QTP+ - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Getting Row & Column data from MS-Word document QTP+ (/Thread-Getting-Row-Column-data-from-MS-Word-document-QTP)



Getting Row & Column data from MS-Word document QTP+ - shriqtp - 08-04-2009

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


RE: Getting Row & Column data from MS-Word document QTP+ - Saket - 08-04-2009

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.


RE: Getting Row & Column data from MS-Word document QTP+ - shriqtp - 08-05-2009

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


RE: Getting Row & Column data from MS-Word document QTP+ - Saket - 08-05-2009

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


RE: Getting Row & Column data from MS-Word document QTP+ - shriqtp - 08-05-2009

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


RE: Getting Row & Column data from MS-Word document QTP+ - Saket - 08-05-2009

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.


RE: Getting Row & Column data from MS-Word document QTP+ - shriqtp - 08-05-2009

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


RE: Getting Row & Column data from MS-Word document QTP+ - Saket - 08-05-2009

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


RE: Getting Row & Column data from MS-Word document QTP+ - shriqtp - 08-05-2009

Did a small mistake while using Replace.

But now it is working absolutely fine.

Thanks a lot....Saket

Have a nice day
Bye