Beruflich Dokumente
Kultur Dokumente
myxl.Workbooks.Add
wait 2
'close Excel
myxl.Application.Quit
Set myxl=nothing
⇒Create an Excel File , Enter some data , Save the Excel and close the
Excel:
'Make sure that you have created an excel file before exeuting the
script.
'Use the path of excel file in the below code
'Also make sure that your excel file is in Closed state before exeuting
the script.
myxl.Workbooks.Open "D:\qtp.xls"
myxl.Application.Visible = true
'this is the name of Sheet in Excel file "qtp.xls" where data needs
to be entered
set mysheet = myxl.ActiveWorkbook.Worksheets("Sheet1")
'Make sure that you have created an excel file before exeuting the
script.
'Use the path of excel file in the below code
'Also make sure that your excel file is in Closed state
myxl.Workbooks.Open "D:\qtp.xls"
myxl.Application.Visible = true
'this is the name of Sheet in Excel file "qtp.xls" where data needs
to be entered
set mysheet = myxl.ActiveWorkbook.Worksheets("Sheet1")
'Close Excel
myxl.Application.Quit
Mismatch=0
Set myxl = createobject("excel.application")
Set mysheet1=Workbook1.Worksheets("Sheet1")
Set mysheet2=Workbook2.Worksheets("Sheet1")
If Mismatch=0 Then
Msgbox "No Mismach exists"
End If
myxl.Quit
set myxl=nothing
'Make sure that you have created an excel file before exeuting the
script.
'Use the path of excel file in the below code
'Also make sure that your excel file is in Closed state before
executing the script.
myxl.Workbooks.Open "D:\qtp.xls"
myxl.Application.Visible = true
'This is the name of Sheet in Excel file "qtp.xls" where data needs
to be entered
set mysheet = myxl.ActiveWorkbook.Worksheets("Sheet1")
'Contents of Sheet1
'Name Age
'Ram 20
'Raghu 15
'Close Excel
myxl.Application.Quit
myxl.Quit
set myxl=nothing
⇒Addsheet Method:
Description: Adds the specified sheet to the run-time Data Table and returns the sheet so
that you can directly set properties of the new sheet in the same statement.
Syntax: DataTable.AddSheet(SheetName)
Example:
datatable.GetSheet("Qtpworld").AddParameter "age","18"
wait 5
⇒DeleteSheet Method:
Description: Deletes the specified sheet from the run-time Data Table.
Example:
datatable.DeleteSheet("Global")
wait 3
⇒Import Method:
Description: Imports the specified Microsoft Excel file to the run-time Data Table.
Syntax: DataTable.Import(FileName)
⇒Export Method:
Description: Saves a copy of the run-time Data Table in the specified location.
Syntax: DataTable.Export(FileName)
Example:
'After the operations are done,you can export the all the qtp
datasheets to the External file
'Create a datatable sheet during Run time.This sheet will be available
during run time only.
datatable.Export "C:\qtptest.xls"
'We can view this sheet in Result Summary under section "Run Time
data Table" .
datatable.AddSheet("Qtpworld")
datatable.DeleteSheet("Global")
wait 3
⇒Value Property:
Description: DataTable default property. Retrieves or sets the value of the cell in the
specified parameter and the current row of the run-time Data Table.
⇒ImportSheet Method:
Description: Imports a sheet of a specified file to a specified sheet in the run-time Data
Table. The data in the imported sheet replaces the data in the destination sheet (see
SheetDest argument).
⇒ExportSheet Method:
Description: Exports a specified sheet of the run-time Data Table to the specified file.
If the specified file does not exist, a new file is created and the specified sheet is saved.If
the current file exists, but the file does not contain a sheet with the specified sheet name,
the sheet is inserted as the last sheet of the file.
If the current file exists and the file contains the specified sheet, the exported sheet
overwrites the existing sheet.
Example:
wait 2
'Apply the logic: if age is less than 18 then the guy is " Minor"
else "Major"
row =datatable.GetSheet("Sheet1").GetRowCount
For i = 1 to row
datatable.GetSheet("Sheet1").SetCurrentRow(i)
If datatable.Value("Age","Sheet1") > 18 Then
datatable.Value("Result","Sheet1") = "Major"
Else
datatable.Value("Result","Sheet1") = "Minor"
End If
Next
' After exporting you can see that the excel file now has been updated
with result
⇒GetSheet Method:
Description: Returns the specified sheet from the run-time Data Table.
Syntax: DataTable.GetSheet(SheetID)
Example given below
⇒GetSheetCount Method:
Description: Returns the total number of sheets in the run-time Data Table.
Syntax: DataTable.GetSheetCount
⇒GetCurrentRow Method:
Description: Returns the current (active) row in the first sheet in the run-time Data Table
(global sheet).
Syntax: DataTable.GetCurrentRow
⇒GetRowCount Method:
Description: Returns the total number of rows in the longest column in the first sheet in
the run-time Data Table (global sheet).
Syntax: DataTable.GetRowCount
⇒SetCurrentRow Method:
Description: Sets the specified row as the current (active) row in the run-time Data Table.
Syntax: DataTable.SetCurrentRow(RowNumber)
Example:
datatable.AddSheet("Qtpworld")
'To add column name and a default value under them.
datatable.GetSheet("Qtpworld").AddParameter "name","Ram"
datatable.GetSheet("Qtpworld").AddParameter "age","18"
datatable.Value("age","Qtpworld")="23"
datatable.GetSheet("Qtpworld").SetCurrentRow(Drow)
Msgbox datatable.Value("name","Qtpworld")
Msgbox datatable.Value("age","Qtpworld")
Next
⇒GlobalSheet Property:
Description: Returns the first sheet in the run-time Data Table (global sheet).
Syntax: DataTable.GlobalSheet
⇒LocalSheet Property:
Description: Returns the current (active) local sheet of the run-time Data Table.
Syntax: DataTable.LocalSheet
Example:
'To add column name in Global Sheet and a default value under them.
datatable.GlobalSheet.AddParameter "name","ramu"
datatable.GlobalSheet.AddParameter "age","18"
'To add column name in Local Sheet and a default value under them.
datatable.LocalSheet.AddParameter "name","Rakesh"
datatable.LocalSheet.AddParameter "age","22"
wait 5