我有来自git的以下代码,它在eclipse中100%工作。它在控制台上将excel文件吐出为Xml格式。当我将其复制/粘贴到soapUI Groovy脚本并点击播放时,我看不到任何事情发生。我尝试用println
替换log.info
但没有用,所以我试图将xml返回到变量中,但我无法弄清楚如何执行此操作,因为它看起来像需要发生在课外 - >我对如何从main
获取信息到testCase属性感到困惑。我还尝试使用testRunner
内部main
和class
内部的import org.apache.poi.ss.usermodel.*
import org.apache.poi.hssf.usermodel.*
import org.apache.poi.xssf.usermodel.*
import org.apache.poi.ss.util.*
import org.apache.poi.ss.usermodel.*
import java.io.*
class GroovyExcelParser {
//http://poi.apache.org/spreadsheet/quick-guide.html#Iterator
def parse(path) {
InputStream inp = new FileInputStream(path)
Workbook wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt(0);
Iterator<Row> rowIt = sheet.rowIterator()
Row row = rowIt.next()
def headers = getRowData(row)
def rows = []
while(rowIt.hasNext()) {
row = rowIt.next()
rows << getRowData(row)
}
[headers, rows]
}
def getRowData(Row row) {
def data = []
for (Cell cell : row) {
getValue(row, cell, data)
}
data
}
def getRowReference(Row row, Cell cell) {
def rowIndex = row.getRowNum()
def colIndex = cell.getColumnIndex()
CellReference ref = new CellReference(rowIndex, colIndex)
ref.getRichStringCellValue().getString()
}
def getValue(Row row, Cell cell, List data) {
def rowIndex = row.getRowNum()
def colIndex = cell.getColumnIndex()
def value = ""
switch (cell.getCellType()) {
case Cell.CELL_TYPE_STRING:
value = cell.getRichStringCellValue().getString();
break;
case Cell.CELL_TYPE_NUMERIC:
if (DateUtil.isCellDateFormatted(cell)) {
value = cell.getDateCellValue();
} else {
value = cell.getNumericCellValue().toInteger();
}
break;
case Cell.CELL_TYPE_BOOLEAN:
value = cell.getBooleanCellValue();
break;
case Cell.CELL_TYPE_FORMULA:
value = cell.getCellFormula();
break;
default:
value = ""
}
data[colIndex] = value
data
}
def toXml(header, row) {
def obj = "<object>\n"
row.eachWithIndex { datum, i ->
def headerName = header[i]
obj += "\t<$headerName>$datum</$headerName>\n"
}
obj += "</object>"
}
public static void main(String[]args) {
def filename = 'RaNdOmxlsxFile.xslx'
GroovyExcelParser parser = new GroovyExcelParser()
def (headers, rows) = parser.parse(filename)
System.out.println 'Headers'
System.out.println '------------------'
headers.each { header ->
System.out.println header
}
System.out.println "\n"
System.out.println 'Rows'
System.out.println '------------------'
rows.each { row ->
System.out.println parser.toXml(headers, row)
}
}
}
变量作为getter和setter,但是......错误,错误和更多错误等。
感谢您的反馈
<asp:RadioButtonList ID="id" runat="server">
<asp:ListItem Selected="True" Value="0">Item 1</asp:ListItem>
<asp:ListItem Value="1">Item 2</asp:ListItem>
</asp:RadioButtonList>
答案 0 :(得分:0)
基本上是多种方式来实现相同的目标:
System.out.println()
替换log.info
并从类中删除main方法。然后运行 groovy脚本。希望你只想看到输出文字。