Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Groovy使用ApachePOI从xlsx获取值_Groovy_Apache Poi_Soapui_Xlsx_Apache Commons - Fatal编程技术网

Groovy使用ApachePOI从xlsx获取值

Groovy使用ApachePOI从xlsx获取值,groovy,apache-poi,soapui,xlsx,apache-commons,Groovy,Apache Poi,Soapui,Xlsx,Apache Commons,我尝试将xlsx文件中的值读取到SoapUI 5.4.0中的属性 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 Exc

我尝试将xlsx文件中的值读取到SoapUI 5.4.0中的属性

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 ExcelReader {

  def readData() {
        def path = "C:\\docs\\data.xlsx";
        InputStream inputStream = new FileInputStream(path);
        Workbook workbook = WorkbookFactory.create(inputStream);
        Sheet sheet = workbook.getSheetAt(0);

        Iterator rowIterator = sheet.rowIterator();
        rowIterator.next()
        Row row;                       
        def rowsData = []
        while(rowIterator.hasNext()) {
             row = rowIterator.next()
             def rowIndex = row.getRowNum()
             def colIndex;
             def rowData = []
             for (Cell cell : row) {
                 colIndex = cell.getColumnIndex()
                  rowData[colIndex] = cell.getRichStringCellValue().getString();
             }                    
             rowsData << rowData
         }
         rowsData
  }
 }

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def myTestCase = context.testCase

ExcelReader excelReader = new ExcelReader();
List rows = excelReader.readData();
def d = []
Iterator i = rows.iterator();
while( i.hasNext()){
         d = i.next();
         myTestCase.setPropertyValue("From", d[0])
         myTestCase.setPropertyValue("To", d[1])       
         testRunner.runTestStepByName( "ConversionRate")

}
执行脚本时,我收到错误消息:

org.apache.poi.ooxml.POIXMLException: org.apache.xmlbeans.XmlOptions.setEntityExpansionLimitILorg/apache/xmlbeans/XmlOptions; 第39行出错


第39行:列表行=excelReader.readData

我的建议是-利用可用的Fillo jar并连接到XLS以获取数据。

需要以下进口:

import com.codoid.products.exception.FilloException;
import com.codoid.products.fillo.Connection;
import com.codoid.products.fillo.Fillo;
import com.codoid.products.fillo.Recordset;

抛出那种错误。我怀疑这是一个java.lang.NoSuchMethodError:org.apache.xmlbeans.XmlOptions.setEntityExpansionLimitILorg/apache/xmlbeans/XmlOptions;。但该方法在xmlbeans-3.0.2.jar中的XmlOptions中。那么xmlbeans-3.0.2.jar是从哪里来的呢?是正确的吗?或者classpath中还有其他jar也在导出org.apache.xmlbeans.XmlOptions吗?@AxelRichter:没有,我是在收到错误消息后添加的。我从中得到了所有的JAR。你能在某处得到异常的完整堆栈跟踪吗?可能有错误日志?java.lang.NoSuchMethodError只是我的一个怀疑。@AxelRichter:我没有其他任何东西,日志输出是清晰的。那么你就迷路了。在某个地方必须有异常的完整堆栈跟踪。但通常情况下,用户应该支持的工具会阻碍用户,因为它们会抑制错误消息。也许一些groovy或soapui专家可以告诉您如何获取异常的完整堆栈跟踪。我不是这样的专家,看起来还可以。我在你的回答中加了一些内容。
import com.codoid.products.exception.FilloException;
import com.codoid.products.fillo.Connection;
import com.codoid.products.fillo.Fillo;
import com.codoid.products.fillo.Recordset;