1

I am very new to Apache POI. I am using Apache version 3.15. I am trying to read the .xlsm file. My code is as below. The error I am getting is different than the other link. Also the solution given in that duplicate link ([Apache POI Parsing error]) is not working for me.

    String fileToRead_String = "C:\\Users\\vchaudh1\\Template\\template.xlsm";
    File fileToRead_File = new File(fileToRead_String);
    try{
        FileInputStream fIP = new FileInputStream(fileToRead_File);
        System.out.println("fIP.available() ="+ fIP.available());
        XSSFWorkbook workbook;
        workbook = new     XSSFWorkbook(fIP);


        FileOutputStream fileout = new FileOutputStream(fileToRead_String);
        fileout.write(10);
        workbook.write(fileout);
        fileout.close();
        System.out.println("xlsm created successfully........");
        workbook.close();

    }
    catch(FileNotFoundException  e){
        System.out.println("exception is:::"+e);
    }

I am getting following error at the line "workbook = new XSSFWorkbook(fIP);"

  ServletWrappe E com.ibm.ws.webcontainer.servlet.ServletWrapper service Uncaught service() exception thrown by servlet ActionServlet: java.lang.IllegalAccessError: Class org/apache/poi/openxml4j/opc/PackageRelationshipCollection illegally accessing "protected" member of class org/apache/poi/util/POILogger
at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.parseRelationshipsPart(PackageRelationshipCollection.java:313)
at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.<init>(PackageRelationshipCollection.java:163)
at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.<init>(PackageRelationshipCollection.java:131)
at org.apache.poi.openxml4j.opc.PackagePart.loadRelationships(PackagePart.java:561)
at org.apache.poi.openxml4j.opc.PackagePart.<init>(PackagePart.java:109)
at org.apache.poi.openxml4j.opc.PackagePart.<init>(PackagePart.java:80)
at org.apache.poi.openxml4j.opc.PackagePart.<init>(PackagePart.java:125)
at org.apache.poi.openxml4j.opc.ZipPackagePart.<init>(ZipPackagePart.java:78)
at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:243)
at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:684)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:275)
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:37)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:266)

Can anybody please suggest me anything where I am doing wrong? or what am I missing here?

  • I was using different version jars earlier but now I am trying using same version jars still it is not working. – user6451593 Aug 09 '17 at 15:40
  • Just some sanity check... Do you have appropriate import statements? `import org.apache.poi.ss.usermodel.*;` and `import org.apache.poi.xssf.usermodel.*`? All poi JARs are of same version? (I have a demo and it is using POI 3.9, poi-ooxml 3.9 and poi-ooxml-schemas 3.9.) – Just a HK developer Aug 10 '17 at 06:23
  • Your versions are still inconsistent. Last version where code line 313 in PackageRelationshipCollection.java (org.apache.poi.openxml4j.opc.PackageRelationshipCollection.parseRelationshipsPart) has called logger, was 3.13 BETA1. In version 3.15 this code line is `try {`. – Axel Richter Aug 10 '17 at 10:08
  • Thanks all of you for the reply. I was using same version for all the JARs which I have kept in my classpath. I copied all the JARs and put it in WEB-INF/lib folder and now it is working. Thanks – user6451593 Aug 11 '17 at 14:06

0 Answers0