No XMLEventFactory.newFactory () method when creating Groovy Script to read .xlsx files on IntelliJ IDEA with JDK 1.8

I am trying to make a groovy script that reads specific .xlsx files and parses them. I want to use Apache POI, but I have several problems. If I try to run the script from IntelliJ IDEA on Mac OS X using JDK 1.8 with POI @Grab annotation 3.11 (previous versions won't load due to xml-apis dependency issues) this is what happens

Caught: java.lang.NoSuchMethodError: 

javax.xml.stream.XMLEventFactory.newFactory()Ljavax/xml/stream/XMLEventFactory;
java.lang.NoSuchMethodError: javax.xml.stream.XMLEventFactory.newFactory()Ljavax/xml/stream/XMLEventFactory;

      

However, the same code in the console throws:

Caught: java.lang.NoClassDefFoundError: org/openxmlformats/schemas/spreadsheetml/x2006/main/CTExtensionList
java.lang.NoClassDefFoundError: org/openxmlformats/schemas/spreadsheetml/x2006/main/CTExtensionList
Caused by: java.lang.ClassNotFoundException: org.openxmlformats.schemas.spreadsheetml.x2006.main.CTExtensionList

      

This is the code I'm trying to run:

import org.apache.poi.xssf.usermodel.XSSFSheet
import org.apache.poi.xssf.usermodel.XSSFWorkbook

@Grapes([
        @Grab(group='org.apache.poi', module='poi', version='3.11'),
        @Grab(group='org.apache.poi', module='poi-ooxml', version='3.11'),
        @Grab(group='org.apache.poi', module='poi-ooxml-schemas', version='3.11')
])
    def path = args[0]
    File file = new File(path)

    XSSFWorkbook workbook = new XSSFWorkbook(file)
    XSSFSheet sheet = workbook.getSheetAt(0)
    println sheet.getRow(2).getCell(2).getStringCellValue()

      

Where can the problem arise?

+3


source to share





All Articles