1

I want to use XLConnect package, however, I am facing unexpected issues.

library(XLConnect)
wb <- XLConnect::loadWorkbook("file.xlsx")
Error: NoClassDefFoundError (Java): org/apache/poi/openxml4j/exceptions/InvalidFormatException

Does anyone know what is happening?

Julia
  • 241
  • 1
  • 8
  • Do you have "Java Runtime Environment (JRE), version 6 or higher" installed. Check the vignette at https://cran.r-project.org/web/packages/XLConnect/vignettes/XLConnect.pdf section 2.1 – Peter Jul 08 '20 at 09:05

1 Answers1

1

There two possible causes to this issue that I know of:

Java dependency conflict

If you have installed a package that also relies on Apache POI, such as xlsx, incorrect classes will be loaded. If you restart your R session and avoid loading the conflicting package, this issue should be avoided.

Failed download of java dependencies

Once you have installed XLConnect (using version 1.0.4 currently on CRAN), check that the java directory under the package's installation[0] contains the following:

ls /your/library/path/XLConnect/java/
commons-codec-1.15.jar    commons-compress.jar  curvesapi-1.06.jar  poi.jar        poi-ooxml-schemas.jar  XLConnect-1.0.3.jar
commons-collections4.jar  commons-math3.jar     ooxml-schemas.jar   poi-ooxml.jar  SparseBitSet.jar       xmlbeans.jar

If one of these is missing, remove the package, restart your R session, and reinstall the package. Check for any errors that occur in that last step.

[0] to find your library path, run .libPaths() in your R session.