An exception occurs when java uses poi to read excel. javapoi reads excel.
A recent web project needs to complete a small function. It uploads files and then reads the file content and writes them to the database. Here, excel files are operated. excel files are assigned two suffixes, version 03 and later versions of xlsx. Now we generally use very useful plug-ins directly. Here we use java poi-related resource packages.
1. to read an excel file with xlsx, you must import the following jar package
The problem is that there is no exception in a test created under the local project. Both types of excel files can be read, but once published to the web project, my project runs under tomcat. A problem occurs here, always reporting this exception:
Exception in thread "main" org. apache. poi. poifs. filesystem. officeXmlFileException: The supplied data appears to be in the Office 2007 + XML. you are calling the part of POI that deals with OLE2 Office Documents ENTs. you need to call a different part of POI to process this data (eg XSSF instead of HSSF)
Then, with the exception coming up, I finally found an xbean. if the jar version is correct, I will know that it may be a jar package conflict, but the structure of the web project is not very clear at this time. Why is there no problem in the test class, but why does this exception occur when running under the web? The reason is that we need to understand that when running under the web, in the webRoot under the WEB-INF below the lib put jar is used when the project runs jar, so this time I went to find, and found that there is an xbean. jar and java poi xmlbeans-2.3.0.jar conflict, decisively Delete the earlier version of xbean. jar to solve the problem.
From this point of view, we should first learn to find the cause from the exception, and then learn how to solve the problem after knowing the cause. Exceptions often expose the key to solving the problem. Hope you can help your friends with this similar problem.