2016-04-22 171 views

回答

0

在某个位置(例如:“C:\ TestResults \”文件夹)中创建带有“测试ID”,“测试结果”列的Excel工作表。

创建函数写测试结果到Excel片为每个测试

呼叫,在每个脚本结束起作用

Function WriteResulttoExcel(ID, TestResult, SheetPath) 
    'Creating the Excel Object 
    set objExcel = createobject("excel.application") 
    'Creating the Workbooks object 
    set objWB = objExcel.workbooks.open (SheetPath) 
    'Creating the sheet object 
    set objsheet = objwb.worksheets(1) 
    ' Write test results to excel sheet 
    rws=objsheet.UsedRange.Rows.count 
    objsheet.cells(1,rws+1).Value= ID 
    objsheet.cells(2,rws+1).Value= TestResult 
    'Saving the workbook after changes 
    objWb.save 
    'closing the workbook 
    objWB.close 
'Quit the Excel and destroying the Excel object 
    objExcel.Quit 
    set objExcel=nothing 
End Function 
1

我认为最简单的方法是将数据写入内置的DataTable,然后将DataTable导出到Excel文件。

例如...

首先,添加一列(aka参数)。这也将第一个数据记录添加到列中。

'add a new column 
DataTable.GetSheet("Global").AddParameter "TestResult", passOrFail 

然后,如果你需要添加更多的记录...

currentRow = DataTable.GetCurrentRow 
DataTable.SetCurrentRow = currentRow + 1 

DataTable.Value("TestResult","Global") = AnotherPassOrFail 

一旦这样做,只是数据表导出到Excel工作表

DataTable.Export "c:\filename.ext" 

你去那里。

相关问题