(WorkbookFactory/create java.io.File) will cause this java.io.IOException: java.lang.NoSuchMethodException: org.apache.poi.xssf.usermodel.XSSFWorkbookFactory.createWorkbook(java.io.File) WorkbookFactory.java:354 org.apache.poi.ss.usermodel.WorkbookFactory.createWorkbook WorkbookFactory.java:314 org.apache.poi.ss.usermodel.WorkbookFactory.createXSSFWorkbook WorkbookFactory.java:173 org.apache.poi.ss.usermodel.WorkbookFactory.create
Sounds like you are running with different versions of Apache POI somehow, either there is a difference between compile-time and run-time or you have mixed versions of the various poi-jars. Please check your setup. If you think this is really caused by Apache POI, please provide some test-project which allows to reproduce this as there is no way to reproduce this for now.
https://poi.apache.org/apidocs/dev/org/apache/poi/xssf/usermodel/XSSFWorkbookFactory.html Is this method createWorkbook(java.io.File) missing? Only see this createWorkbook(java.io.File, boolean)
That method only exists in the parent class, org.apache.poi.ss.usermodel.WorkbookFactory From the source you can see that it defaults to readOnly=false when calling org.apache.poi.xssf.usermodel.XSSFWorkbookFactory Further, org.apache.poi.xssf.usermodel.XSSFWorkbookFactory has never implemented the method createWorkbook(File), only ever inheriting that method from WorkbookFactory. It's all there in the source and SVN history if you care to investigate. As Dominik said above, it sounds like your classpath has multiple different POI JAR files in it. This kind of runtime only error is almost always due to stale JARs in the classpath and/or differences between compile and run class loading - e.g. IDE configuration vs deployment server/container configuration.
Yeah how silly I was. I should have looked into the parent class. poi 4.0.1 was the only library pulled from maven. This is the only thing I'm sure of: there was no library version issue. I check my .m2 folder and it's the same verdict. I'm not able to reproduce the issue I guess we'll leave it there. Sorry about this bug report.
This is still an issue.
According to the source https://svn.apache.org/repos/asf/poi/trunk/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java In method createWorkbook(String, Object[]) it will try to look for org.apache.poi.xssf.usermodel.XSSFWorkbookFactory.createWorkbook(java.io.File, Boolean). When the method is not found it's not found exception is thrown https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getMethod-java.lang.String-java.lang.Class...- private static Workbook createXSSFWorkbook(Object... args) throws IOException, EncryptedDocumentException { return createWorkbook("org.apache.poi.xssf.usermodel.XSSFWorkbookFactory", args); } /** * Does the actual call to HSSF or XSSF to do the creation. * Uses reflection, so that this class can be in the Core non-OOXML * POI jar without errors / broken references to the OOXML / XSSF code. */ private static Workbook createWorkbook(String factoryClass, Object[] args) throws IOException, EncryptedDocumentException { try { Class<?> clazz = WorkbookFactory.class.getClassLoader().loadClass(factoryClass); Class<?>[] argsClz = new Class<?>[args.length]; int i=0; for (Object o : args) { Class<?> c = o.getClass(); if (Boolean.class.isAssignableFrom(c)) { c = boolean.class; } else if (InputStream.class.isAssignableFrom(c)) { c = InputStream.class; } else if (File.class.isAssignableFrom(c)) { c = File.class; } argsClz[i++] = c; } Method m = clazz.getMethod("createWorkbook", argsClz); return (Workbook)m.invoke(null, args);
It seems you are trying to call the WorkbookFactory.create() with a "File" object, which is not supported. There is currently a method create(Object), which you can call with any object, but only "OPCPackage" is supported according to it's javadoc description. Also this method is scheduled to be removed in one of the next releases. Please show the code that you use to invoke the WorkbookFactory.
Change 1832358 in Bug #62355 seems related, we changed interface from OPCPackage to Object for one method in order to support Java 11 properly, however this seems to break cases where you now try to provide a "File" as "Object" somehow in the parameters and thus the wrong method is selected for execution. We have tests that create(File) still works as expected, so something in your code seems to trigger this and so it most likely will need some modification there to be fixed.
I am using Clojure interop I call it essentially this way: (WorkbookFactory/create java.io.File) which gives this java.io.IOException: java.lang.NoSuchMethodException: org.apache.poi.xssf.usermodel.XSSFWorkbookFactory.createWorkbook(java.io.File) WorkbookFactory.java:354 org.apache.poi.ss.usermodel.WorkbookFactory.createWorkbook WorkbookFactory.java:314 org.apache.poi.ss.usermodel.WorkbookFactory.createXSSFWorkbook WorkbookFactory.java:173 org.apache.poi.ss.usermodel.WorkbookFactory.create here's the signature: https://poi.apache.org/apidocs/dev/org/apache/poi/ss/usermodel/WorkbookFactory.html#create-java.io.File- examples here "Files vs InputStreams" section: https://poi.apache.org/components/spreadsheet/quick-guide.html perhaps a .xlsx file will trigger this according to source code and stacktrace.
Perhaps i was calling create(java.lang.Object pkg) method as you point out? Let me try to give it a type hint.
that's exactly the case.... i'm sorry.... i was doing a file upload in clojure ring. this fails (let [file (:tempfile req) ;; wb (XSSFWorkbookFactory/createWorkbook file false) wb (WorkbookFactory/create file) this works (let [file (:tempfile req) ;; wb (XSSFWorkbookFactory/createWorkbook file false) wb (WorkbookFactory/create ^java.io.File file)