|
|
|
|
Write in Excel
|
|
05-24-2010, 09:45 AM
Post: #1
|
|||
|
|||
|
Write in Excel
Hi, I have a query regarding writing data in Excel. I was able to write the data in excel but when i navigate to other web page then it over writes the previous data. Please tell me the way so that i can write the data in excel without overwriting the previous data. Hope it explains my problem........... Regards, Anu |
|||
|
05-24-2010, 11:12 AM
Post: #2
|
|||
|
|||
|
RE: Write in Excel
Hi Anu,
would you like to elaborate the query, exactly what you need to write into excel and paste your code whatever you have tried so far. It will help us to understand better. Thanks, ~Saket Kumar [Linkedin][pdf Api for QTP] It's so hard when I have to, and so easy when I want to... |
|||
|
05-24-2010, 02:31 PM
Post: #3
|
|||
|
|||
RE: Write in Excel
(05-24-2010 09:45 AM)Anu Wrote: Hi, Two ways to handle this, 1. Either use newer rows while navigating to the next webpage 2. Use a different sheet. Whichever should suit your need... Basanth QTP On Unix- Java Way - Without Putty or Terminal Emulation You have no idea how high I can fly... |
|||
|
05-25-2010, 09:43 AM
Post: #4
|
|||
|
|||
|
RE: Write in Excel
Hi Saket,
Below is the code.......................... Dim xlSheet,xlBook, xlApp,a,CustomerName,Address,datatable Const ForAppending = 8 const TristateTrue=-1 file_location = "F:\Test.xls" Dim iCol : iCol = 0 '———-’For Wirting in Excel Sheet’ Set xlApp = CreateObject("Excel.Application") Set xlBook = xlApp.WorkBooks.Open("F:\Test.xls") Set xlSheet = xlBook.WorkSheets("Sheet1") CountOfRows=Browser("Meghalaya Directory Search").Page("Meghalaya Directory Search_3").WebTable("DataTable").WebTable("Table").RowCount iCol = iCol + 1 For i = 1 To CountOfRows CustomerName=Browser("Meghalaya Directory Search").Page("Meghalaya Directory Search_3").WebTable("DataTable").WebTable("Table").GetCellData(i,3) Address=Browser("Meghalaya Directory Search").Page("Meghalaya Directory Search_3").WebTable("DataTable").WebTable("Table").GetCellData(i,4) xlSheet.Rows(i).Columns(iCol).Value =CustomerName xlSheet.Rows(i).Columns(iCol + 1).Value =Address iNewcolumn=xlSheet.UsedRange.Columns.Count + 1 Next 'xlBook.Save 'xlBook.Close 'xlApp.Quit Browser("Meghalaya Directory Search").Page("Meghalaya Directory Search_3").WebTable("LinkTable").Link("2").Click Here i have parameterized the Link(“2″) that is in the object repository. When i run the script then it automatically goes to the next link and write data to excel sheet by overwritting the previous data. My problem is that-”I want data should not overwrite instead it should get append same as happen if we write data in txt” Hope this explains my problem………………… Regards, Anu ------------------------------------------------------------------------ (05-24-2010 11:12 AM)Saket Wrote: Hi Anu, |
|||
|
05-25-2010, 11:08 AM
Post: #5
|
|||
|
|||
|
RE: Write in Excel
You should use usedrange to append the data in your xls
1. identify the used range in the sheet 2. start adding value from the very next row. it woult be like below Code: nRow = xlSheet.UsedRangebtw, what exactly you do with the this statement Code: iNewcolumn=xlSheet.UsedRange.Columns.Count + 1do you execute this everytime a new link clicked? Thanks, ~Saket Kumar [Linkedin][pdf Api for QTP] It's so hard when I have to, and so easy when I want to... |
|||
|
05-25-2010, 11:26 AM
(This post was last modified: 05-25-2010 12:06 PM by Anu.)
Post: #6
|
|||
|
|||
|
RE: Write in Excel
Hi,
Some one has told me to use "iNewcolumn=xlSheet.UsedRange.Columns.Count + 1" this for adding the data in the new cloumn of same excel but it does not work from my side. Thanks For urs prompt reply................ ![]() Regards, Anu Hi Saket, I have tried the same code given by you.......... It is not adding the value to the next row. The code given by you is below: nRow = xlSheet.UsedRange For i = 1 To CountOfRows CustomerName=Browser("Meghalaya Directory Search").Page("Meghalaya Directory Search_3").WebTable("DataTable").WebTable("Table").GetCellData(i,3) Address=Browser("Meghalaya Directory Search").Page("Meghalaya Directory Search_3").WebTable("DataTable").WebTable("Table").GetCellData(i,4) nRow = nRow + 1 xlSheet.Rows(nRow).Columns(iCol).Value =CustomerName xlSheet.Rows(nRow).Columns(iCol + 1).Value =Address iNewcolumn=xlSheet.UsedRange.Columns.Count + 1 Next Waiting for response......... Regards, Anu Hi Saket, Your question : Do you execute this everytime a new link clicked? Answer: Please elaborate it......... Regards, Anu |
|||
|
05-25-2010, 12:43 PM
Post: #7
|
|||
|
|||
|
RE: Write in Excel
I am so sorry, surprised how I missed this
, here is the corrected codeCode: nRow = xlSheet.UsedRange.Rows.CountThanks, ~Saket Kumar [Linkedin][pdf Api for QTP] It's so hard when I have to, and so easy when I want to... |
|||
|
05-25-2010, 12:54 PM
(This post was last modified: 05-28-2010 09:42 AM by Anu.)
Post: #8
|
|||
|
|||
|
RE: Write in Excel
Hi Saket,
Thnks Regards, Anu Hi Saket, This code is working but at the same time it is showing the error which is attached herewith. Please tell me how to handle this error Regards, Anu |
|||
|
05-25-2010, 03:19 PM
Post: #9
|
|||
|
|||
|
RE: Write in Excel
Hi Saket,
Could you please look into this query on urgent basis. Hope you understand. Thanks in advance ![]() Regards, Anu |
|||
|
05-25-2010, 03:21 PM
Post: #10
|
|||
|
|||
|
RE: Write in Excel
check if your xls is checked read only. make it read/write, you will be able to use it.
Thanks, ~Saket Kumar [Linkedin][pdf Api for QTP] It's so hard when I have to, and so easy when I want to... |
|||
|
« Next Oldest | Next Newest »
|
| Possibly Related Threads... | |||||
| Thread: | Author | Replies: | Views: | Last Post | |
| Write in Excel Continued | Anu | 3 | 641 |
08-27-2010 08:53 AM Last Post: basanth27 |
|
| Write Heading in excel | Anu | 28 | 3,625 |
08-05-2010 03:02 PM Last Post: Anu |
|
User(s) browsing this thread: 1 Guest(s)
|
|

Search
Member List
Calendar
Help




