'输出数据到excle中
exclefile = "D:\QTP\reg\reguser"®now&".xls"
Set ExcelObj = CreateObject("Excel.Application")
ExcelObj.Workbooks.Add '增加一个工资表
Set NewSheet = ExcelObj.Sheets.Item(1) '取得新添加的工作表
NewSheet.Name = "reguser" '重命名工作表名字
row = 1 '从第一行开始
NewSheet.Cells(1,1) = "username"
NewSheet.Cells(1,2) = "password"
NewSheet.Cells(2,1) = DataTable("long_name", dtGlobalSheet)®now
NewSheet.Cells(2,2) = DataTable("password", dtGlobalSheet)®now
NewSheet.Columns("A:A").ColumnWidth = 20 '宽度
NewSheet.Columns("A:A").Font.Bold = True '加粗
NewSheet.Columns("B:B").ColumnWidth = 20
NewSheet.Columns("B:B").HorizontalAlignment = -4108 ' 剧中
'保存文件,exclefile为文件路径
ExcelObj.ActiveWorkbook.SaveAs exclefile
ExcelObj.Quit
Set ExcelObj = Nothing
'--------------------------------------------------------------------------------------------
'输出内容到已经存在的excle中-----------------------------------------
xlsworkname ="reguser" '工作表名称
workbookurl="D:\QTP\reg\" & xlsworkname & ".xls" 'excle文件路径
Set ExcelObj = CreateObject("Excel.Application") ' 创建excle工作表对象
ExcelObj.Visible = False '激活工作表
Set xlsWorkBook = ExcelObj.Workbooks.Open(workbookurl) '打开excle文件
Set NewSheet = xlsWorkBook.Sheets(xlsworkname) '选择添加数据的工作表
row = 1 '从第一行开始
Do
'msgbox(NewSheet.cells(row,1)) '调试语句
If NewSheet.Cells(row,1) ="" then '写入数据
NewSheet.Cells(row,1) = DataTable("long_name", dtGlobalSheet)®now
NewSheet.Cells(row,2) = DataTable("password", dtGlobalSheet)®now
exit do
end if
row = row + 1
loop
xlsWorkBook.Save ''保存文件
xlsWorkBook.close '关闭工作表
Set xlsWorkBook = Nothing
'--------------------------------------------------------------------------------------------
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) | Powered by Discuz! X3.2 |