Results 1 to 6 of 6

Thread: Datatable: Creation, Writing and Reading the values from Excel Sheet

  1. #1
    Junior Member
    Join Date
    Sep 2007
    Answers
    13

    Datatable: Creation, Writing and Reading the values from Excel Sheet

    Hi Friends,

    I am practicing QTP and currently working with Datatable.

    Please help me in writing a descriptive program for storing the information in excel sheet for the following scenarios:

    Scenarios:

    1) Creation of excel sheet (at run time).
    2) Storing the datas (user name and password) into the excel sheet by creating it (at run time).
    3) Reading the datas (user name and password) from the above said excel sheet (at run time).


    I tried, but I was not successful for all the three.

    I am waiting for your replies.....


  2. #2
    Expert Member
    Join Date
    Sep 2007
    Answers
    110

    Re: Datatable: Creation, Writing and Reading the values from Excel Sheet

    Hi,

    ''''Creation of Excel Sheet'''''''''''

    Set Excel=createObject("Excel.Application")
    Set ExcelSheet=createObject("Excel.sheet")
    ExcelSheet.Application.visible=true

    '''''storing the datas into excel sheet'''''''''''

    Excel.ActiveSheet.cells(1,1).value="UserName"
    Excel.ActiveSheet.cells(1,2).value="Password"
    Excel.ActiveSheet.cells(2,1).value="arunsingh"
    Excel.ActiveSheet.cells(2,2).value="rajaputra"
    ExcelSheet.SaveAs "C:/text1.xls"
    datatable.Import "C:/text1.xls"

    '''''Reading the datas from excel sheet'''''''

    msgbox "UserName is= "+datatable(1,1)
    msgbox "PassWord is= "+datatable(2,1)

    ____________________
    Arunsingh Rajaputra


  3. #3

    Re: Datatable: Creation, Writing and Reading the values from Excel Sheet

    '''''Reading the datas from excel sheet'''''''

    msgbox "UserName is= "+datatable(1,1)
    msgbox "PassWord is= "+datatable(2,1)
    Rajaputra, this code will only read data from QTP's DataTable, not an Excel Sheet.

    This is a very simple code, but it works. You can read single cell data using this code but this is not a very good alternative if you have lots of data in your Excel Sheet.

    Function ReadExcel (nRow, nCol)

    Set oExcel = CreateObject("Excel.Application")
    Set oWorkBook = oExcel.Workbooks.Open("C:\testFile.xls")
    Set oSheet = oWorkBook.Activesheet
    strVal = oSheet.Cells (nRow, nCol).Value

    End Function


    Last edited by Anshoo_Arora; 02-28-2008 at 11:30 PM.

  4. #4
    Expert Member
    Join Date
    Sep 2007
    Answers
    110

    Re: Datatable: Creation, Writing and Reading the values from Excel Sheet

    Anshoo,
    Yes, The last 2 lines in my code is reading data from datatable.

    You can use below line to read the data from excell sheet......

    msgbox "UserName is= "+Excel.ActiveSheet.cells(2,1)
    msgbox "Password is= "+Excel.ActiveSheet.cells(2,2)

    _____________
    ArunSingh Rajaputra


  5. #5
    Junior Member
    Join Date
    Jan 2009
    Answers
    21

    Re: Datatable: Creation, Writing and Reading the values from Excel Sheet

    Hi rajaputra,

    i've tried the same code for writing into excel sheet. at first it worked. But, now it is not working. it is giving this error message.

    object required: 'Excel.ActiveSheet'


    Can you please help me what do i have to do now.


    Quote Originally Posted by rajaputra View Post
    Hi,

    ''''Creation of Excel Sheet'''''''''''

    Set Excel=createObject("Excel.Application")
    Set ExcelSheet=createObject("Excel.sheet")
    ExcelSheet.Application.visible=true

    '''''storing the datas into excel sheet'''''''''''

    Excel.ActiveSheet.cells(1,1).value="UserName"
    Excel.ActiveSheet.cells(1,2).value="Password"
    Excel.ActiveSheet.cells(2,1).value="arunsingh"
    Excel.ActiveSheet.cells(2,2).value="rajaputra"
    ExcelSheet.SaveAs "C:/text1.xls"
    datatable.Import "C:/text1.xls"

    '''''Reading the datas from excel sheet'''''''

    msgbox "UserName is= "+datatable(1,1)
    msgbox "PassWord is= "+datatable(2,1)

    ____________________
    Arunsingh Rajaputra



  6. #6
    Expert Member
    Join Date
    Apr 2008
    Answers
    1,859

    Re: Datatable: Creation, Writing and Reading the values from Excel Sheet

    hai jyothipola,

    Will you please post your code what you have tried here.

    Thanks
    Deepa


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact