|
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
--------------------------------------------------------------------------------
Problem Description: How to add formatting to the cell in an Excel document
--------------------------------------------------------------------------------
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 |
|