Forum Discussion
DavidEtcell
12 years agoOccasional Contributor
This is sloppy, and missing the classes you'll need to import, but what you want probably looks something like:
A few points, 65 through 68 for i are just trivial numbers, where 65 = A, 66 = B, if you have 10 columns A to J, its 65 through 74, so put 75 in the loop condition part of the for statement.
Anyway, this assumes the DataSource is called "DataSource", and referrs to a file called "C:\files\DatabaseName.xls".
def file = new File('C:\\files\\DatabaseName.xls').canonicalPath
def xls = new ActiveXObject('Excel.Application')
def workbooks = xls.Workbooks
def workbook = workbooks.Open(file)
def sheet = workbook.ActiveSheet
def source = testRunner.testCase.getTestStepByName("DataSource")
def thiscolumn
for(i=65;i<69;i++){
thiscolumn = i as char
source.addProperty(sheet.Range(thiscolumn+"1").Value)
}
A few points, 65 through 68 for i are just trivial numbers, where 65 = A, 66 = B, if you have 10 columns A to J, its 65 through 74, so put 75 in the loop condition part of the for statement.
Anyway, this assumes the DataSource is called "DataSource", and referrs to a file called "C:\files\DatabaseName.xls".