Theres a few problems here, but lets start with the easy one, the for loop.
Ok, the confusion here, is that in my script, I have assumed the ROW number with the column headers is 1.
This is the "1" in the 'source.addProperty(sheet.Range(thiscolumn+"1").Value)' line.
So if you want row 36, this line would be 'source.addProperty(sheet.Range(thiscolumn+"36").Value)'.
Now, the C part.
Check out an ascii table like this:
http://www.ascii-code.com/Look at the DEC and Description columns. In the for loop, you want to start at the DEC number for your column, so if you want C36, this is dec 67.
I'm not sure where you want your column headers to stop, so lets say the column headers are C-M. you need the DEC number of M+1 for the condition part of the for loop.
So given the information:
C = 67
M= 77
M+1 = 78
ROW = 36The code looks like:
for(i=
67;i<
78;i++){
thiscolumn = i as char
source.addProperty(sheet.Range(thiscolumn+"
36").Value)
}
for(i=67;i<78;i++){
thiscolumn = i as char
source.addProperty(sheet.Range(thiscolumn+"36").Value)
}
Ok, now for the error you are getting. You appear to be trying to get a sheet object directly off the file
instead of:
def sheet = file.getSheet("CreateOrg"); just use
def sheet = workbook.getSheet("CreateOrg")Having said THAT thoug, I am pretty sure getSheet is not a scriptom method, at least not like that. Try:
def sheet = workbook.Sheets.Item["CreateOrg"]Anyway, at the end of the day, the script will look like this:
import org.codehaus.groovy.scriptom.*
def source = testRunner.testCase.getTestStepByName("CreateOrgValidations DataSource")
def file = new File("O:\\Technology & Telecommunications\\Application Development\\Applications Integration & Implementation\\Testing Team\\Projects\\Australia Post\\7.5 New Temp Permit - Decision Tree.xls").canonicalPath
def xls = new ActiveXObject('Excel.Application')
def sheet = new ActiveXObject("Excel.Sheet")
def workbooks = xls.Workbooks
def workbook = workbooks.Open(file)
sheet = workbook.Sheets.Item["CreateOrg"]
//log.info thesheet.Name
String thiscolumn //or def if you dont want it cast yet
for(i=67;i<78;i++){
thiscolumn = i as char
source.addProperty(sheet.Range(thiscolumn + "36").Value)
//log.info sheet.Range(thiscolumn + "36").Value
}
workbook.close(false, null, false)
xls.Quit()
Scriptom.releaseApartment()
If the ascii value thing is still confusing you try this:
import org.codehaus.groovy.scriptom.*
def source = testRunner.testCase.getTestStepByName("CreateOrgValidations DataSource")
def file = new File("O:\\Technology & Telecommunications\\Application Development\\Applications Integration & Implementation\\Testing Team\\Projects\\Australia Post\\7.5 New Temp Permit - Decision Tree.xls").canonicalPath
def xls = new ActiveXObject('Excel.Application')
def sheet = new ActiveXObject("Excel.Sheet")
def workbooks = xls.Workbooks
def workbook = workbooks.Open(file)
sheet = workbook.Sheets.Item["CreateOrg"]
//log.info thesheet.Name
String FirstColumn = "C"
String LastColumn = "M"
String thiscolumn //or def if you dont want it cast yet
for(i=(int)FirstColumn;i<((int)LastColumn)+1;i++){
thiscolumn = i as char
source.addProperty(sheet.Range(thiscolumn + "36").Value)
//log.info sheet.Range(thiscolumn + "36").Value
}
workbook.close(false, null, false)
xls.Quit()
Scriptom.releaseApartment()
I haven't checked that though, but should work unless I've forgotten something simple..