Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to compare excel with datatatble
#1
Solved: 11 Years, 4 Months, 3 Weeks ago
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
Reply
#2
Solved: 11 Years, 4 Months, 3 Weeks ago
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
Reply
#3
Solved: 11 Years, 4 Months, 3 Weeks ago
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
Reply
#4
Solved: 11 Years, 4 Months, 3 Weeks ago
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.
Reply
#5
Solved: 11 Years, 4 Months, 3 Weeks ago
Thanks that was really very neatly explained.

iam really thankful.

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare WebTable Elements saraiado 1 2,581 06-11-2015, 06:54 PM
Last Post: venkatesh9032
  How to compare two binary values Naresh 0 2,369 09-09-2014, 05:06 PM
Last Post: Naresh
  Compare a link name to a column in Excel mv8167 4 3,948 01-23-2012, 07:39 PM
Last Post: mv8167
  How do I compare 2 text files? avanthika 4 15,174 12-10-2011, 09:03 PM
Last Post: Arul
  How do I do an image compare? typeOpositive 2 5,502 12-08-2010, 06:00 PM
Last Post: typeOpositive

Forum Jump:


Users browsing this thread: 1 Guest(s)