Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Write Heading in excel
#11
Solved: 10 Years, 8 Months, 2 Weeks ago
Hi,

I used array for Header but while writing it into the excel the code given by you is :
*** Writing Header***'
Code:
sHeaderList = Split(sHeader,",")
    i = 0
    For Each sHeader in sHeaderList
        i = i + 1
        ExcelSheet.ActiveSheet.Cells(1, i).Value = sHeader
    Next

As i declared header as array then what changes should i do in the above code as i am getting confuse between sHeader & sHeaderList.
Please explain me so that i can proceed further.
Thanks in advance...................

Regards,
Anu
Reply
#12
Solved: 10 Years, 8 Months, 2 Weeks ago
Since in my example I have kept all headers in a single string with comma separated , I had used Split function to get individual header. Now you should omit that line...
Ex: If your array name is "sHeaderArray" then...
*** Writing Header***'
Code:
i = 0
For Each sHeader in sHeaderArray
i = i + 1
ExcelSheet.ActiveSheet.Cells(1, i).Value = sHeader
Next
Reply
#13
Solved: 10 Years, 8 Months, 2 Weeks ago
Hi,

I have done the modifications as per your reply. But not able to write in excel
However for writing in excel code is little bit different from yours code......
Code:
'For Wirting in Excel Sheet’
Dim xlApp, xlBook, xlSheet ,sHeaderArray()
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.WorkBooks.Open("F:\Test.xls")
Set xlSheet = xlBook.WorkSheets("Sheet1")
'*** Writing Header***'
      i = 0
    For Each sHeader in sHeaderArray
        i = i + 1
        ExcelSheet.ActiveSheet.Cells(1, i).Value = sHeader
    Next
' Save the sheet.
xlBook.Save
' Close Excel with the Quit method on the Application object.
xlApp.DisplayAlerts = False
xlApp.Quit
' Release the object variable.
Set ExcelSheet = Nothing
Set objExcel = Nothing

I am using the above code. Could ypu please tell me why is it not writting the header to excel.
Waiting for reply..........

Regads,
Anu
Reply
#14
Solved: 10 Years, 8 Months, 2 Weeks ago
Are you getting values and storing it in sHeaderArray before you running this logic? And after running above code, are you getting any run time error? If not, is the "F:\Test.xls" exists after you run?
Reply
#15
Solved: 10 Years, 8 Months, 2 Weeks ago
Hi,

I did not get you.................Sad
Reply
#16
Solved: 10 Years, 8 Months, 2 Weeks ago
you said "why is it not writting the header to excel.?", to make it more clear... You are using one array to keep your headings , right?
so before you write to excel sheet, I just wanted to confirm if your array contains any value?
like sHeaderArray(0) = "test", etc...
Reply
#17
Solved: 10 Years, 8 Months, 2 Weeks ago
No, it did not contain any value.
I declare it as Dim sHeaderArray()
Please correct me if i declare it in a worng way.
Waiting for early reply...........

Regards,
Anu
Reply
#18
Solved: 10 Years, 8 Months, 2 Weeks ago
Are you able to get the search result headings using QTP? If so, can you provide your code that you are using to get the search result headings?
Reply
#19
Solved: 10 Years, 8 Months, 2 Weeks ago
i did not understand but i am pasting the code which i am using :
CODE:---------------------------------------
Code:
SystemUtil.Run "F:\Program Files\Internet Explorer\iexplore.exe","","F:\Documents and Settings\Anu","open"
Browser("Browser").Page("Page").Sync
Browser("Browser").Navigate "http://google.com/"
Browser("Browser").Page("Google").WebEdit("q").Set "header"
Browser("Browser").Page("Google").WebEdit("q").Submit
'For Wirting in Excel Sheet’
Dim xlApp, xlBook, xlSheet ,sHeaderArray()
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.WorkBooks.Open("F:\Test.xls")
Set xlSheet = xlBook.WorkSheets("Sheet1")
'*** Writing Header***'
      i = 0
    For Each sHeader in sHeaderArray
        i = i + 1
        ExcelSheet.ActiveSheet.Cells(1, i).Value = sHeader
    Next
' Save the sheet.
xlBook.Save
' Close Excel with the Quit method on the Application object.
xlApp.DisplayAlerts = False
xlApp.Quit
' Release the object variable.
Set ExcelSheet = Nothing
Set objExcel = Nothing
Reply
#20
Solved: 10 Years, 8 Months, 2 Weeks ago
ok, after submit, use GetROProperty method to get the search result headings, if the properties of the page are not uniquely identified use descriptive programing. and keep them in a array. See the example, do not take as it is , try urself and apply your logic.
Ex:
Code:
Dim sHeaderArray(100)
For i = 0 to n 'specify your limit for value of n
sHeaderArray(i) =  Browser("Browser").Page("Google").Link().GetROProperty("text")
Next
After you have value in your array, use the logic to write the header in your excel.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Write in Excel Continued Anu 3 3,155 08-27-2010, 08:53 AM
Last Post: basanth27
  Write in Excel Anu 48 28,609 08-25-2010, 06:08 PM
Last Post: Saket

Forum Jump:


Users browsing this thread: 1 Guest(s)