试用版不能用CSO么??作者: lovetest6 时间: 2006-4-24 18:05
Products: Mercury QuickTest Professional 5.x and Mercury QuickTest Professional 6.x
Issue: How to use Excel objects in a QuickTest Professional test
Solution: Refer to Microsoft`s MSDN Library for a complete listing of Excel Object`s methods and properties
You can refer to "Microsoft Excel 2000 Visual Basic for Applications object model" for a complete listing of Excel methods and properties that can be used within a QuickTest Professional (QTP) script. You can use these Excel object methods within a QTP script to create workbooks, create new sheets, input data, etc.
For a complete listing of Excel object's methods and properties, refer to MSDN Library - Microsoft Excel Object Model (http://msdn.microsoft.com/librar ... elApplication.asp).
The following is a sub-procedure that uses Excel object methods to output data from a dictionary object to an Excel file. Attached you will find a working example of a QuickTest Professional test that uses the sub-procedure below. The example will retrieve information from a webpage and output it to an Excel file (info.xls) using the ReportInformation sub-procedure.
In order to run the test, unzip the attached file to a temporary folder, and start QTP with web support loaded:
CPT31467.zip
Example:
Sub ReportInformation(dictionary, filename)
' create the Excel object
Set ExcelObj = CreateObject("Excel.Application")
' add a new Workbooks and a new Sheet
ExcelObj.Workbooks.Add
Set NewSheet = ExcelObj.Sheets.Item(1)
NewSheet.Name = "Page Information"
' loop through all the information in the Dictionary object
' and report it to the Excel sheet
row = 1
For Each key In dictionary.keys
NewSheet.Cells(row,1) = key
NewSheet.Cells(row,2) = dictionary(key)
row = row + 1
Next
' save the Excel file
ExcelObj.ActiveWorkbook.SaveAs filename
' close the application and clean the object
ExcelObj.Quit
Set ExcelObj = Nothing
End Sub
Note:
Excel's object methods are not part of QuickTest Professional, therefore, they are not guaranteed to work and are not supported by Mercury Technical Support. Any changes that Microsoft may make to these methods are not the responsibility of Mercury.
Login to Mercury Customer Support to access these Related articles:
Problem ID 34574 - How to add cells, rows, or columns to an Excel document
Problem ID 28214 - How to get data from an Excel file without importing the data to the data table
Problem ID 41551 - How to run an Excel macro from QuickTest Professional
Problem ID 28332 - How to write data to an Excel file without importing the data to the data table
Problem ID 44128 - How to set the number format of cells in an Excel file
Problem ID 43591 - How to hide/display columns or rows in an Excel document
Problem ID 43589 - How to change the font and cell color in an Excel document
Problem ID 43645 - How to add formatting to the cell in an Excel document
» Printer Friendly Version作者: aries1979 时间: 2006-4-25 13:29
谢谢版主,不过我要的是后面提到的几篇文档,谢谢
Problem ID 34574 - How to add cells, rows, or columns to an Excel document
Problem ID 28214 - How to get data from an Excel file without importing the data to the data table
Problem ID 41551 - How to run an Excel macro from QuickTest Professional
Problem ID 28332 - How to write data to an Excel file without importing the data to the data table
Problem ID 44128 - How to set the number format of cells in an Excel file
Problem ID 43591 - How to hide/display columns or rows in an Excel document
Problem ID 43589 - How to change the font and cell color in an Excel document
Problem ID 43645 - How to add formatting to the cell in an Excel document
因为注册CUSTOMER SUPPORT要一个什么号,应该是只有正版的才行作者: lovetest6 时间: 2006-4-26 13:55
Problem ID: 43645
--------------------------------------------------------------------------------
Product:
QTP Version N/A
Ext(s):
Add-in Not Applicable
Topics:
Actions and External Libraries Problems or Questions
VBScript Problems, Questions, or Examples
OS:
Any Windows Platform
Creation Date:
14 Dec 2005 Last Modified Date:
15 Dec 2005
Solution: Formatting Excel output from QuickTest Professional
You can use the Excel object model to automate formatting the values in a cell in an Excel worksheet. For more information on using the Excel object model with QuickTest Professional, refer to Problem ID 31468 - How to use Excel objects in a QuickTest Professional test.
Example:
filename = "C:\temp\Book1.xls"
Set ExcelObj = CreateObject("Excel.Application")
ExcelObj.Workbooks.Open filename
Set NewSheet = ExcelObj.Sheets.Item(1)
' Add the text - format bold
NewSheet.Cells(1,2) = "Hello From QTP!"
NewSheet.Cells(1,2).Font.Bold = true
' Add the text - format color
NewSheet.Cells(2,2) = "Hello From QTP!"
NewSheet.Cells(2,2).Font.Color = RGB(0, 0, 255)
' Add the text - format italic
NewSheet.Cells(3,2) = "Hello From QTP!"
NewSheet.Cells(3, 2).Font.Italic = true
' Add the text - format size
NewSheet.Cells(4,2) = "Hello From QTP!"
NewSheet.Cells(4, 2).Font.Size = 25
' Add the text - format Strikethrough
NewSheet.Cells(5,2) = "Hello From QTP!"
NewSheet.Cells(5, 2).Font.Strikethrough = true
' Add the text - format underline
NewSheet.Cells(6,2) = "Hello From QTP!"
NewSheet.Cells(6, 2).Font.Underline = true
' Add the text - format Subscript
NewSheet.Cells(7,2) = "1st test"
NewSheet.Cells(7, 2).Characters(2, 2).Font.Subscript = True
' Add the text - format Subscript
NewSheet.Cells(8,2) = "1st test"
NewSheet.Cells(8, 2).Characters(2, 2).Font.Superscript = True
ExcelObj.ActiveWorkbook.Save
ExcelObj.Application.Quit
Set ExcelObj = Nothing
Related articles:
Problem ID 31468 - How to use Excel objects in a QuickTest Professional test
Problem ID 34574 - How to add cells, rows, or columns to an Excel document
Problem ID 28332 - How to write data to an Excel file without importing the data to the data table
Problem ID 28214 - How to get data from an Excel file without importing the data to the data table
Problem ID 43589 - How to change the font and cell color in an Excel document
Problem ID 43591 - How to hide/display columns or rows in an Excel document作者: lovetest6 时间: 2006-4-26 14:34
点我签名上的link