fenwickr
10 years agoOccasional Contributor
How to writing to a New EXCELL TAB with Groovy
When I write my log to a excell file
I use the code below
def reportFileName = context.expand( '${#TestSuite#reportFileName}' )
fileName = new File(reportFileName)
result = "$testSuiteName,$total,$passed,$failed\r\n"
fileName.exists() ? fileName.append(result) : fileName.write(result)
how can I write to a new tab/spreadsheet in the excell file
Hi Fenwickr,
Please take a look at this code posted by Sandeepss here:
import jxl.*; import jxl.write.* Workbook workbook = Workbook.getWorkbook(new File("d:\\NewExcel.xls")); WritableWorkbook copy = Workbook.createWorkbook(new File("d:\\NewExcel.xls"),workbook); Sheet sheet1 = copy.getSheet("Sheet4"); WritableSheet sheet2 = copy.getSheet("Sheet1"); CL = 0; rows = sheet1.getRows(); for( tc_row in 1..rows-1){ WritableCell tmpA = sheet1.getCell(CL,tc_row); String s1 = tmpA.getContents(); log.info("$s1") Label label = new Label(CL,tc_row,s1); sheet2.addCell(label); } copy.write(); copy.close(); workbook.close();
It adds some data to the specified sheet.