我是编码新手,下面是我在Soap UI中使用的用于将响应数据转储到excel工作表中的Groovy脚本。我在第55行的'}'处遇到错误,如果条件关闭(我认为这不是问题)。早些时候我仅使用jexl,并且工作正常,但后来我切换到poi以便能够将数据附加到同一张纸中,并且会引发错误。我已经在bin/ext中复制了所有相关的jar。
import java.io.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.*;
import jxl.*;
def grUtils = new com.eviware.soapui.support.GroovyUtils(context)
def ReqHolder = grUtils.getXmlHolder("Search#Response")
def HotelCount = ReqHolder["count(//*:Property)"]
def tCNo = context.expand( '${DSS#TCNo.}' )
if (tCNo =='1')
{
FileInputStream fsIP= new FileInputStream(new File("C:/Users/129858/Desktop/Soap/Simplify_HTE/SearchSink.xls"));
HSSFWorkbook copy = new HSSFWorkbook(fsIP);
HSSFSheet worksheet = copy.getSheetAt(0);
CL = 0;
rows = HotelCount.toInteger();
Cell cell = null;
cell = worksheet.getRow(0).getCell(0);
cell.setCellValue("TCNo.");
cell = worksheet.getRow(0).getCell(1);
cell.setCellValue("HotelName");
cell = worksheet.getRow(0).getCell(2);
cell.setCellValue("HotelCode");
cell = worksheet.getRow(0).getCell(3);
cell.setCellValue("BrandCode");
for( tc_row in 1..rows){
Cell box = null;
cell = worksheet.getRow(tc_row).getCell(CL);
String s0 = tCNo;
cell.setCellValue(s1);
cell = worksheet.getRow(tc_row).getCell(CL+1);
String s1 = ReqHolder.getNodeValue("//*:Property[$tc_row]/@HotelName");
cell.setCellValue(s1);
cell = worksheet.getRow(tc_row).getCell(CL+2);
String s2 = ReqHolder.getNodeValue("//*:Property[$tc_row]/@HotelCode");
cell.setCellValue(s2);
cell = worksheet.getRow(tc_row).getCell(CL+3);
String s3 = ReqHolder.getNodeValue("//*:Property[$tc_row]/@BrandCode");
cell.setCellValue(s3);
}
fsIP.close();
FileOutputStream fsOP =new FileOutputStream(new File("C:/Users/129858/Desktop/Soap/Simplify_HTE/SearchSink.xls");
copy.write(fsOP);
fsOP.close();
}
else{
FileInputStream file = new File("C:/Users/129858/Desktop/Soap/Simplify_HTE/SearchSink.xls");
HSSFWorkbook wb = new HSSFWorkbook(file);
HSSFsheet ws = wb.getSheetAt(0):
datarows = ws.getRows();
col = 0;
log.info datarows
exrows = HotelCount.toInteger() + datarows + 1;
log.info exrows
for( tc_ro in datarows+1..exrows)
{
Cell box = null;
cell = worksheet.getRow(tc_ro).getCell(col);
String s0 = tCNo;
cell.setCellValue(s1);
cell = worksheet.getRow(tc_ro).getCell(col+1);
String s1 = ReqHolder.getNodeValue("//*:Property[$tc_row]/@HotelName");
cell.setCellValue(s1);
cell = worksheet.getRow(tc_ro).getCell(col+2);
String s2 = ReqHolder.getNodeValue("//*:Property[$tc_row]/@HotelCode");
cell.setCellValue(s2);
cell = worksheet.getRow(tc_ro).getCell(col+3);
String s3 = ReqHolder.getNodeValue("//*:Property[$tc_row]/@BrandCode");
cell.setCellValue(s3);
}
fsIP.close();
FileOutputStream fsOP =new FileOutputStream(new File("C:/Users/129858/Desktop/Soap/Simplify_HTE/SearchSink.xls");
copy.write(fsOP);
fsOP.close();
}
最佳答案
在第53行中,您缺少一个右括号:
FileOutputStream fsOP =new FileOutputStream(new File("C:/Users/129858/Desktop/Soap/Simplify_HTE/SearchSink.xls");
它应该是:
FileOutputStream fsOP =new FileOutputStream(new File("C:/Users/129858/Desktop/Soap/Simplify_HTE/SearchSink.xls"));
第91行也发生了同样的事情。
考虑使用带有代码验证和完成功能的编辑器。您可以从多种免费的IDE中进行选择,例如IntelliJ IDEA,Eclipse,Netbeans等。例如,IDEA会很快告诉您,您缺少此结束括号,并且可以节省大量时间。
关于groovy - 使用poi.jar作为数据接收器脚本时出现Groovy编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50965560/