We are trying to read data from xlsx file using apache POI, we have all the jars files placed under soap/bin/ext. It gives us below error when running our groovy script.
org.apache.poi.ooxml.POIXMLException: org.apache.xmlbeans.XmlOptions.setEntityExpansionLimit(I)Lorg/apache/xmlbeans/XmlOptions; error at line: 15
Code:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
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;
import org.apache.poi.ss.usermodel.CellStyle;
FileInputStream inputStream = new FileInputStream("D:\\SOAP\\ExcelPOI.xlsx")
Workbook wb = WorkbookFactory.create(inputStream)
Sheet sheet1 = wb.getSheet("Sheet Name")
int rows = sheet1.getLastRowNum();
log.info(rows)
poi.jar version?
Add this jar file also in bin/ext folder - ooxml-schemas-1.4.jar and then restart your soap ui. If you have already added some version of ooxml-schemas_version_name.jar.. Then remove that. for poi version 4.1.0 you have to use ooxml-schemas-1.4.jar.
Yeah.. actually, you need to keep it in bin/ext folder.. please try again.
It did not work by placing jar file in ext folder. We have added jars files in soap/bin/ext folder for us. We are using SOAP 5.5.0. Thanks
activation-1.1.1
commons-codec-1.12
commons-collections4-4.3
commons-compress-1.18
commons-logging-1.2
commons-math3-3.6.1
curvesapi-1.06
jaxb-api-2.3.0
jaxb-core-2.3.0.1
jaxb-impl-2.3.0.1
junit-4.12
log4j-1.2.17
ooxml-schemas-1.4
poi-4.1.0
poi-examples-4.1.0
poi-excelant-4.1.0
poi-ooxml-4.1.0
poi-scratchpad-4.1.0
xmlbeans-3.1.0
Here is my solution for this problem. Please go through this and try once more please. Remove al the jars form bin/ext folder and add whatever is mentioned in the problem:-
Thanks, Yes this work. We use jlx jars for reading from xls file. So csv and XLS are covered.
We want to read xlsx data using Apache POI using groovy scripting. Any solution for it.
Hi,
Your script works ok in the GroovyConsole with my own xlsx file.
@Grab(group='org.apache.poi', module='poi-ooxml', version='4.1.0') import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; 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; import org.apache.poi.ss.usermodel.CellStyle; FileInputStream inputStream = new FileInputStream("C:/Users/hunti/My Lesson Plan.xlsx") Workbook wb = WorkbookFactory.create(inputStream) Sheet sheet1 = wb.getSheet("Sheet1") int rows = sheet1.getLastRowNum(); println rows //12
Can you post as an attachment the xlsx file you are having trouble with, or just let me know if you have the same problem with an empty/test sheet.
Posting more of the stack trace (as an attachment, please) may also help.