Please ensure to include your code between [code][/code] tags while asking or replying to questions.

Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

How to write a data in excel file

06-07-2011, 05:23 PM
Post: #1
Solved: 8 Months, 2 Weeks, 2 Days, 10 Hours, 3 Minutes, 31 Seconds ago How to write a data in excel file
Hi,

I am new to QTP. I want to create a calculator to test in qtp.

1)Input should be data sheet :
Rows = 20
Column =3
The columns and rows should have numbers

2)The output should be excel with the results of the following functions
Addition, subtraction, division, multiplication

I am able to do step 1,read data from DataTable. using import excel file in DataTable. using calc application, i able to add value but i want to write in excel file.

Code:
strData1 = DataTable.Value(1,1)

Please any one help me to this task.


Thanks & Regards,
Kamalakannan Anandan
Find all posts by this user
Quote this message in a reply
06-07-2011, 06:43 PM
Post: #2
Solved: 8 Months, 2 Weeks, 2 Days, 10 Hours, 3 Minutes, 31 Seconds ago RE: How to write a data in excel file
Hi,
To write in datatable...

Code:
DataTable.Value("column name","sheet name") = result

To export the datatable...

Code:
DataTable.Export "file path"

~vIns~
Find all posts by this user
Quote this message in a reply
06-08-2011, 10:28 AM
Post: #3
Solved: 8 Months, 2 Weeks, 2 Days, 10 Hours, 3 Minutes, 31 Seconds ago RE: How to write a data in excel file
Hi VIns,

Thanks for replying my queries.

I will explain clearly, about my task. I want to create a new test program calculator application. Read data from data table in QTP, i entering data in Default.xls file in my test program folder. Now i am importing the default.xls file in to my global data table in qtp. I am able to read all the rows and colomn, and i able to add data using calculator application. Now i want to write result add, sub, mul and div value to excel data.

Please find the sample code of my program.

'''Code
Code:
Dim nRow
Dim strValue1, strvalue2, strvalue3
Dim strAdd, strSub, strMul, strDiv
Dim Msg1, Msg2, Msg3, Msg4
Dim objFSO, strOutputFilePath
    
strValue1 = Datatable.Value(1, 1)
strValue2 = Datatable.Value(2, 1)
strvalue3 = Datatable.Value(3, 1)

nRow = Datatable.GetCurrentRow

''*****************************************************************************'​''
Code:
''' Addition
Window("Calculator").WinButton("C").Click
Window("Calculator").WinEdit("Edit").Type(strValue1)
Window("Calculator").WinButton("+").Click
Window("Calculator").WinEdit("Edit").Type(strValue2)
Window("Calculator").WinButton("+").Click
Window("Calculator").WinEdit("Edit").Type(strValue3)
Window("Calculator").WinButton("=").Click
strAdd = Window("Calculator").WinEdit("Edit").GetROProperty("text")

Msg1 = MsgBox( "Colomn 1: " & strValue1 &Chr(13) & "Column 2: " & strvalue2 & Chr(13) & "Colomn 3: " & strValue3 & Chr(13) & "Addition Value: " & strAdd , 64, "MyCalc")

I want to write result in excel file. Please help me to solve this issue.



Thanks & Regards,
Kamalakannan Anandan
Find all posts by this user
Quote this message in a reply
08-20-2011, 08:01 PM
Post: #4
Solved: 8 Months, 2 Weeks, 2 Days, 10 Hours, 3 Minutes, 31 Seconds ago RE: How to write a data in excel file
Hi,
Try this

Code:
'Set objExcel = CreateObject("Excel.Application")
'Set objWorkbook = objExcel.WorkBooks.Open("C:\Arul\Automationscripts\Excel-Cell-001")
'Set objDriverSheet = objWorkbook.Worksheets("Name")
'
''then just acces the cell itself :
'row = 1
'a=objDriverSheet.Cells(row,"A").Value
'b=objDriverSheet.Cells(row,"B").Value

regards,
Arul.D
Find all posts by this user
Quote this message in a reply
08-23-2011, 07:00 PM
Post: #5
Solved: 8 Months, 2 Weeks, 2 Days, 10 Hours, 3 Minutes, 31 Seconds ago RE: How to write a data in excel file
Code:
Set ObjExcel=CreateObject("Excel.Application")
  Set objWorkbook = ObjExcel.Workbooks.add
  Set objWorksheet = objWorkbook.Worksheets(1)

   objWorksheet.Name = SheetName
   'ObjExcel.Visible=True

'to write values to the cells....

Code:
objWorksheet.cells(1,1)="Property"
    objWorksheet.cells(1,2)="Validation"
    objWorksheet.cells(1,3)="Outcome"
Find all posts by this user
Quote this message in a reply
08-24-2011, 10:29 AM
Post: #6
Solved: 8 Months, 2 Weeks, 2 Days, 10 Hours, 3 Minutes, 31 Seconds ago RE: How to write a data in excel file
Hi, i think this will help you.
Append the row and write again

Code:
Dim fso
Set fso=CreateObject("Excel.Application")
fso.visible=true
Set excel_obj=fso.workbooks.open("D:\BookingResults\test1.xls")
Set obj_worksheet=excel_obj.worksheets(1)
cell_address=obj_worksheet.UsedRange.Address
add_array1=split(cell_address,":",-1,0)
add_array=Split(add_array1(1),"$",-1,0)
row=add_array(2)+1
col=add_array(1)
obj_worksheet.cells(row,col).activate
obj_worksheet.cells(row,col).value="Hi"

Correct me if wrong.

Regards,
Sankalp
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  How to read and write in excel through QTP script shwetha_m 5 4,535 03-14-2014 02:58 PM
Last Post: venkatesh9032
  How to check whether data exists in excel.. venkatesh9032 1 150 03-06-2014 04:37 PM
Last Post: supputuri
  Importing data from Excel into Data table of QTP Chitti 1 542 11-01-2013 05:54 PM
Last Post: Parke
  Retrieving data from Txt file into datatable kriday 3 586 07-23-2013 11:04 AM
Last Post: vinod123
  Importing data from Excel to Txt File kriday 2 589 07-13-2013 06:52 PM
Last Post: kriday



User(s) browsing this thread: 1 Guest(s)