Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to compare excel with datatatble
#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


Messages In This Thread
how to compare excel with datatatble - by diya - 11-29-2012, 09:18 PM
RE: how to compare excel with datatatble - by kordirko - 12-03-2012, 03:49 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare WebTable Elements saraiado 1 2,580 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,171 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)