我是编码的新手,下面是我在Soap UI中使用的用于将响应数据转储到excel工作表中的常规脚本。我在第55行'}'遇到错误,如果条件关闭(我认为这不是问题)。早些时候我仅使用jexl,并且工作正常,但是后来我切换到poi以便能够将数据附加到同一张纸中,并且会引发错误。我已经将所有相关的jars复制到bin / ext中。
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();
}
答案 0 :(得分:1)
在第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会很快告诉您,您缺少此结束括号,并且可以节省很多时间。
答案 1 :(得分:0)
感谢Stepniak,他指出了我正确的方向。它有太多错误,还有一些糟糕透顶的伪装。现在可以正常工作了。
import java.io.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.ss.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')
{
HSSFWorkbook copy = new HSSFWorkbook();
HSSFSheet worksheet = copy.createSheet("SearchSink");
CL = 0;
rows = HotelCount.toInteger();
Row head = worksheet.createRow(0);
Cell cell0 = head.createCell(0);
cell0.setCellValue("TCNo.");
Cell cell1 = head.createCell(1);
cell1.setCellValue("HotelName");
Cell cell2 = head.createCell(2);
cell2.setCellValue("HotelCode");
Cell cell3 = head.createCell(3);
cell3.setCellValue("BrandCode");
for( tc_row in 1..rows){
Row data = worksheet.createRow(tc_row);
Cell box0 = data.createCell(CL);
String s0 = tCNo;
box0.setCellValue(s0);
Cell box1 = data.createCell(CL+1);
String s1 = ReqHolder.getNodeValue("//*:Property[$tc_row]/@HotelName");
box1.setCellValue(s1);
Cell box2 = data.createCell(CL+2);
String s2 = ReqHolder.getNodeValue("//*:Property[$tc_row]/@HotelCode");
box2.setCellValue(s2);
Cell box3 = data.createCell(CL+3);
String s3 = ReqHolder.getNodeValue("//*:Property[$tc_row]/@BrandCode");
box3.setCellValue(s3);
}
FileOutputStream fsOP =new FileOutputStream(new
File("C:/Users/129858/Desktop/Soap/Simplify_HTE/SearchSink.xls"));
copy.write(fsOP);
fsOP.close();
}
else{
FileInputStream file = new FileInputStream(new
File("C:/Users/129858/Desktop/Soap/Simplify_HTE/SearchSink.xls"));
HSSFWorkbook wb = new HSSFWorkbook(file);
HSSFSheet ws = wb.getSheetAt(0);
int datarows = ws.getLastRowNum();
col = 0;
log.info datarows
exrows = HotelCount.toInteger() + datarows;
log.info exrows
for( tc_ro in datarows+1..exrows)
{
Row data = ws.createRow(tc_ro);
Cell box0 = data.createCell(col);
String s0 = tCNo;
box0.setCellValue(s0);
Cell box1 = data.createCell(col+1);
String s1 = ReqHolder.getNodeValue("//*:Property[$tc_ro-$datarows]/@HotelName");
box1.setCellValue(s1);
Cell box2 = data.createCell(col+2);
String s2 = ReqHolder.getNodeValue("//*:Property[$tc_ro-$datarows]/@HotelCode");
box2.setCellValue(s2);
Cell box3 = data.createCell(col+3);
String s3 = ReqHolder.getNodeValue("//*:Property[$tc_ro-$datarows]/@BrandCode");
box3.setCellValue(s3);
}
file.close();
FileOutputStream fsOP =new FileOutputStream(new
File("C:/Users/129858/Desktop/Soap/Simplify_HTE/SearchSink.xls"));
wb.write(fsOP);
fsOP.close();
}