0

I need to export some data to Excel from a small Grails application. To do so, I have added the following dependencies to my BuildConfig:

    dependencies {            
        compile 'org.apache.poi:poi-ooxml:3.13'
        compile 'org.apache.poi:poi-ooxml-schemas:3.13'
    }

Whenever I try to utilize the libraries, I run into a ClassNotFoundException. The following code reproduces to error:

    Workbook workbook = new XSSFWorkbook()
    Sheet sheet = workbook.createSheet("Title")
    Row row = sheet.createRow(0)
    // Make first header row:
    row.createCell(0).setCellValue("Header1")

The call to row.createCell(0).setCellValue("Header1") Produces the following stacktrace-message:

Class
java.lang.ClassNotFoundException
Message
org.openxmlformats.schemas.spreadsheetml.x2006.main.CTExtensionList

Originally I only included the poi-ooxml but a jar-finder search suggests that the class is included in poi-ooxml-schemas, so I included that as well. It still doesn't work however. The code compiles fine and the error occurs runtime.

Any suggestions? Am I missing something or what?

Hoof
  • 1,738
  • 2
  • 17
  • 39
  • poi-ooxml requires poi as in https://poi.apache.org/overview.html . Add `compile 'org.apache.poi:poi:3.13'` to your dependencies – practical programmer Feb 03 '16 at 09:15
  • It's seems to be downloaded and added as a transitive dependency and it makes no difference to add it explicitly .. – Hoof Feb 03 '16 at 09:42
  • 3
    So I think this is the same as http://stackoverflow.com/questions/10330593/apache-poi-exception-in-reading-xlsx-files . Read http://poi.apache.org/faq.html#faq-N10025 , maybe you need to use full schemas jar – practical programmer Feb 03 '16 at 09:50
  • You are exactly right. I chose to downgrade to 3.9 instead of using the 14+ mb of full schemas... And now it works! :) – Hoof Feb 03 '16 at 10:02
  • Can you post the full stacktrace of the exception? – centic Feb 03 '16 at 14:07

1 Answers1

0

Duplicate post of: apache POI exception in reading xlsx files

Two solutions:

  • Downgrade to 3.9
  • Use the full schemas jar file (~15mb)
Community
  • 1
  • 1
Hoof
  • 1,738
  • 2
  • 17
  • 39