Welcome, Guest. Please login or register.
Login with username, password and session length

 
Advanced search

18120 Posts in 4741 Topics- by 31743 Members - Latest Member: suuraj
 

Pages: [1]   Go Down
Print
0 Members and 1 Guest are viewing this topic.
Author Topic: Comparing word documents    (Read 1379 times)
Maz
FRProject
User
*
Offline Offline

Posts: 11


WWW
« on: October 27, 2007, 10:29:37 AM »

Hi all,

I need to validate the content of two word documents in QTP and don't have any ideas on how to do this.

Both documents need to be checked for their content i.e text, images, etc. These docs come in different sizes ranging from 0.5 to 5MB.

If its not possible to compare the contents I would like to validate the file size of the documents.

Any thoughts appreciated.

Thanks
Maz
Logged
Site Administrator
Administrator
Active User
*****
Offline Offline

Posts: 56



WWW
« Reply #1 on: October 27, 2007, 11:12:21 AM »

It is possible to do so with the Word.Application COM.
You can open a COM interface to a document via the GetObject command, and then use the COM interface to obtain certain properties from the document:

Code
GeSHi (qtp):
Set oDoc = GetObject("C:\FirstDoc.Doc", "Winword.Application")

'For example - save the file's text:

sFirstFileText = oDic.ActiveDocument.Contents.Text

 
Created by GeSHI 1.0.7.20

You can access other properties as well (such as comments, images, fonts etc.) - see the Word MSDN documentation for details. After you've saved the properties from both documents you can simply compare the variables and get your results.

More general properties can be made available via DSO, as described in Dani's article.
Logged

Yaron Assa

AdvancedQTP Site Administrator
Dani Vainstein
Administrator
Advanced User
*****
Offline Offline

Posts: 623



« Reply #2 on: October 27, 2007, 11:26:30 AM »

Please look in the article DsoFile
you can retrieve the numbers of words, lines, formats etc
Logged

Best Regards,
Dani Vainstein
Mercury CPC

http://www.advancedqtp.com
Maz
FRProject
User
*
Offline Offline

Posts: 11


WWW
« Reply #3 on: October 27, 2007, 12:59:53 PM »

Thanks Dani/Site Admin... i'll give it a blast.

Cheers
Maz
Logged
Maz
FRProject
User
*
Offline Offline

Posts: 11


WWW
« Reply #4 on: October 29, 2007, 09:48:49 AM »

I'm trying to get the number of images in a word document -

Set oDoc = CreateObject("Word.Application")

Set oDoc = GetObject("C:\Validation\FirstDoc.rtf", "Word.Document")

docImages = oDoc.Document.Images

... but i'm getting a run-time error - Object doesn't support this property or method: 'oDoc.Document'

http://msdn2.microsoft.com/en-us/library/ms537461.aspx#

Any help appreciated.

Maz
Logged
Site Administrator
Administrator
Active User
*****
Offline Offline

Posts: 56



WWW
« Reply #5 on: October 29, 2007, 10:31:23 AM »

A. You only need the 2nd line (Set oDoc = GetObject("C:\Validation\FirstDoc.rtf", "Word.Document")) to make it work.
B. The link you've provided refers to a web page, not a word document.
The actual object model you want is: Word.Document Com Object. And indeed this object model doesn't have the property you're trying to access.

In Word, pictures are considered to be shapes. So you actually need to access the .Shapes and .InlineShapes collections of the document. In your script, this will translate to accessing the oDoc.Shapes and oDoc.InlineShapes collections respectively.

You can read about the different properties and methods for these collections in this MSDN article (It's for word 2003, but these collections haven't changed much since Office 2000). I hope this is enough to get you started (If not, you can always post new questions under this thread).

Enjoy Smiley

Maybe I'll write an article on the matter in the coming weeks.
Logged

Yaron Assa

AdvancedQTP Site Administrator
Maz
FRProject
User
*
Offline Offline

Posts: 11


WWW
« Reply #6 on: October 29, 2007, 10:59:06 AM »

Thanks for the prompt reponse Yaron. Appreciate your help with this thread.

 Smiley
Maz
Logged
Pages: [1]   Go Up
Print
Jump to: