An exception occurs when java uses poi to read excel. javapoi reads excel.

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.