2016-04-22 170 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" 

你去那裏。

相關問題