我在使用soapui和groovy读取excel中的一些数据,运行到脚本读取数据后无法打开excel,workbook.close()也无济于事。
def ExcelInstance(String testdatapath,String Sheetname) {
try {
wb = WorkbookFactory(new File(testdatapath));
this.sheetname=Sheetname;
for(org.apache.poi.ss.usermodel.Sheet sheet: wb) {
if(Sheetname==sheet.getSheetName())
break;
}
}
catch (Exception e) {
log.info("Exception: ${e}" )
}
}
def releaseExcel(){
wb.close() wb.quit()
}
我想说的是,你没有把wb对象传递给releaseExcel()。
在你调用releaseExcel()的地方,传递wb对象。这意味着调用代码需要它的可见性。所以实例化wb对象的代码需要把这个对象返回给控制代码,然后就可以把它传递为
releaseExcel(wb)