Forum Discussion
Saw this on another post - thought it might be helpful...it's something I'm about to try myself - looks pretty straightforward - 1) define the workbook where the Excel sheet is stored
2) define the sheet name In the workbook (file) as there can be many sheets to a file
3) get the number of rows and columns dynamically and store in arrays to allow to use in loop creation
4) loop through the data first by row and then within each row loop through columns
5) write out the contents of each cell based on the row/cell identifier
-instead of writing out the value - assign the value of the cell to a variable and use it to drive your test
-if you have this in an Excel file the date format is set by the file itself...
import jxl.*
Workbook workbook = Workbook.getWorkbook(new File("D:/SOAPUI/ConversionRate.xls"))
Sheet sheet1 = workbook.getSheet("DataDriven")
def rows = sheet1.getRows()
def cols = sheet1.getColumns()
log.info "Row Count =" + rows
log.info "Column Count =" + cols
for(i=1;i<rows;i++) {
for(j=0;j<cols;j++) {
Cell cell = sheet1.getCell(j,i)
log.info cell.getContents()
}
}
Hope this helped...as I said - I'm new too so ...not sure if there is a formatDate command or such you could use...anyone...?
import jxl.* Workbook workbook = Workbook.getWorkbook(new File("D:/SOAPUI/ConversionRate.xls")) Sheet sheet1 = workbook.getSheet("DataDriven") def rows = sheet1.getRows() def cols = sheet1.getColumns() log.info "Row Count =" + rows log.info "Column Count =" + cols for(i=1;i<rows;i++) { for(j=0;j<cols;j++) { Cell cell = sheet1.getCell(j,i) log.info cell.getContents() } }
Related Content
- 3 years ago
Recent Discussions
- 3 days ago