Micro Focus QTP (UFT) Forums
how to compare excel with datatatble - 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: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: how to compare excel with datatatble (/Thread-how-to-compare-excel-with-datatatble)



how to compare excel with datatatble - diya - 11-29-2012

Hello All,
I have a basic knowledge in QTP.Right now we are learning as well as developing scripts for our application.
I want to retrieve data stored in .xls sheet,first row,first column & compare this retrieved data with the data outputted in the data table in QTP.we are using QTP9.2.Actually the thing is,in our application,we have an 'About' box which displays the version no. of the build.I want to check whether this version no.is correct & as per latest updations in the .xls sheet from developer.So I have used output value to output this version no. in data table.Now i want to comapre the two values,one in the QTP data table & 2nd in the .xls sheet.I have tried many combinations,but all are failing.
Can you please help me put in this.I am not well versed in descriptive programing.
Plz do reply asap.
Thanks..

This was asked by someone i tried but could not get please reply as how to go....
first step would be importing the excel sheet to datatable using
datatable.import

after that please lemme know what to do


RE: how to compare excel with datatatble - kordirko - 12-03-2012

You can import the excel sheet into the data table, here is an example
Code:
DataTable.AddSheet("mysheet")
DataTable.ImportSheet "c:\tmp\file.xls", 1, "mysheet"
1 - means: import 1st sheet from the file
....
but the problem with this method is that QTP treats the first row of the file as columns' headers (names),
so you cannot read values from the first row, you can read values only from the second and subsequent rows.

There is another method - you can open the excel file using directly Excel.Application object,
here is an example:
Code:
Dim objExcel,  objWorkBook
Dim strValue
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = true
Set objWorkBook = objExcel.Workbooks.Open( "c:\tmp\file.xls" )
objExcel.Sheets(1).Select
strValue = objExcel.Cells( 1, 1 ).Value
objWorkBook.Close
objExcel.Quit

Set objWorkBook = Nothing
Set objExcel = Nothing

MsgBox strValue



RE: how to compare excel with datatatble - diya - 12-03-2012

Hello,

Thanks for the reply...

i did not understand what you are tryign to telllis it regarding the import...
then how do i compare please help


RE: how to compare excel with datatatble - kordirko - 12-04-2012

When you import an excel file into QTP table, values stored in first row become column names in QTP table.
For example, if your spreadshed contains these values:
Code:
+------+------+------+------+
|   A  |   B  |   C  |  D   |
+------+------+------+------+
|  a1  |  b1  |  c1  |  d1  |
|  a2  |  b2  |  c2  |  d2  |
|  a3  |  b3  |  c3  |  d3  |
where cell (1,1) contains a1, cell (3,2) contains b3 etc,
then after importing this spreadsheet into the datatable you get:
Code:
+------+------+------+------+
|  a1  |  b1  |  c1  |  d1  |
+------+------+------+------+
|  a2  |  b2  |  c2  |  d2  |
|  a3  |  b3  |  c3  |  d3  |
where cell (1,1) contains value a2, cell (2,2) contains b3 etc.
Values from the first row in the excel spreadsheet are used as column names in QTP datatable.


RE: how to compare excel with datatatble - diya - 12-04-2012

Thanks that was really very neatly explained.

iam really thankful.

trying to do the comparison...trying out but not getting it