是否有使用了SoapUI的免费版本5.3.0与Apache的POI-3.14的限制阅读XLSX文件?

2019-10-29 08:18发布

是否有一个限制读XLSX文件? 随着XLS文件,我面对任何问题。

我的环境是:

  • 了SoapUI免费版本5.3.0
  • Apache的POI 3.14
  • Windows 7中的Pro / Office 2010中

Apache的POI库的位置

I unzipped the downloaded POI package into the following folder:
C:\Program Files\SmartBear\SoapUI-5.3.0\bin\ext
fyi - I have also tried adding it to lib

错误我得到当我试图运行下面提供的Groovy脚本是:

org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException

我的Groovy脚本是:

import java.io.File;
import java.io.FileInputStream;
import java.util.Iterator;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;

String filepath = "E:\\SoapUiProjects\\MyWorkspace\\data\\data.XLSX"
String sheetName = "login"
FileInputStream fis = new FileInputStream(new File(filepath))

Workbook wb = WorkbookFactory.create(fis)
Sheet sh = wb.getSheet(sheetName)

Iterator itrRow = sh.rowIterator()
while(itrRow.hasNext())
{
    Row row = itrRow.next()
    for(Cell cell : row)
    {
        switch(cell.getCellType())
        {
            case Cell.CELL_TYPE_NUMERIC:
                log.info cell.getNumericCellValue()
                break;
            default:
                log.info cell.getRichStringCellValue()
        }       
    }   
}

fis.close()
wb.close()

堆栈跟踪:

2017-07-11 15:09:50,631 ERROR [SoapUI] An error occurred [java.lang.reflect.InvocationTargetException], see error log for details
2017-07-11 15:09:50,631 ERROR [errorlog] org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
    at org.apache.poi.POIXMLFactory.createDocumentPart(POIXMLFactory.java:65)
    at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:601)
    at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:174)
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:249)
    at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:211)
    at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:170)
    at org.apache.poi.ss.usermodel.WorkbookFactory$create.call(Unknown Source)
    at Script21.run(Script21.groovy:14)
    at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:90)
    at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:141)
    at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:250)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:56)
    at org.apache.poi.POIXMLFactory.createDocumentPart(POIXMLFactory.java:62)
    ... 13 more
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.apache.poi.POIXMLTypeLoader
    at org.apache.poi.xssf.model.ThemesTable.<init>(ThemesTable.java:85)
    ... 19 more

先感谢您。

Answer 1:

下面当POI-OOXML罐子不可抛出异常

java.lang.NoClassDefFoundError: Could not initialize class org.apache.poi.POIXMLTypeLoader

我已经加入库皂UI ext文件夹下面。

C:\Program Files\SmartBear\SoapUI-5.3.0\bin\ext

图书馆

commons-collections4-4.1.jar
ooxml-schemas-1.3.jar
ooxml-security-1.1.jar
openxml4j-1.0-beta.jar
poi-3.16.jar
poi-contrib-3.6.jar
poi-examples-3.16.jar
poi-excelant-3.16.jar
poi-ooxml-3.16.jar
poi-ooxml-schemas-3.16.jar
poi-scratchpad-3.16.jar

您的代码对我的作品的罚款。

Groovy代码

import java.io.File;
import java.io.FileInputStream;
import java.util.Iterator;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;

String filepath = "D:\\testdata\\TestData.xlsx"
String sheetName = "Sheet1"
FileInputStream fis = new FileInputStream(new File(filepath))

Workbook wb = WorkbookFactory.create(fis)
Sheet sh = wb.getSheet(sheetName)

Iterator itrRow = sh.rowIterator()
while(itrRow.hasNext())
{
    Row row = itrRow.next()
    for(Cell cell : row)
    {
        switch(cell.getCellType())
        {
            case Cell.CELL_TYPE_NUMERIC:
                log.info cell.getNumericCellValue()
                break;
            default:
                log.info cell.getRichStringCellValue()
        }       
    }   
}

fis.close()
wb.close()

输出:

Sat Jul 29 08:00:54 SGT 2017:INFO:VarName
Sat Jul 29 08:00:54 SGT 2017:INFO:URL
Sat Jul 29 08:00:54 SGT 2017:INFO:DBURL
Sat Jul 29 08:00:54 SGT 2017:INFO:https://www.stackoverflow.com
Sat Jul 29 08:00:54 SGT 2017:INFO:Test


文章来源: Is there a limitation reading XLSX file using SoapUI free version 5.3.0 & Apache poi-3.14?