Java reads Excel exception problems with POI

Source: Internet
Author: User

Recently a Web project needs to complete a small function, the use of file upload and then read the contents of the file to write to the database, here is the operation of the Excel file, Excel files are divided into two suffixes, 03 version of the XLS and after the xlsx, now we generally take very good plug-ins directly to use it, I'm Using a Java poi-related resource Pack.

1, first to be able to read the Excel file with xlsx, You must import the following jar package

Then the problem is that a test-class test built under local engineering is not an exception, and both Excel files can be read, but once published to Web engineering, my project runs under Tomcat. There is a problem here, always report this exception:

Exception in thread "main" org.Apache. Poi.poifs.filesystem.OfficeXmlFileException:The supplied data appears To is in the Office 2007+ XML. You is calling the part of the POI this deals with OLE2 Office Documents. You need the different part of the POI to process this data (eg XSSF instead of Hssf)

And then with an unusually careful look upwards, Finally found that there is a xbean.jar is the correct version, this time I know it might be a jar package conflict, but at this point on the structure of the Web project is not very clear, why in the test class is not a problem, but why in the Web run when the exception is generated, the reason, here to understand, run under the web time, under the Webroot under the web-inf below the Lib Jar is the project run time used to use the jar, so I went to find, sure enough to find a Xbean.jar and Java Poi Xmlbeans-2.3.0.jar conflict, Decisively delete the lower version of the xbean.jar, problem solving.

therefore, from the experience of this problem, the first thing to learn from the anomaly to find the reason, and then know the reason for how to Solve. Anomalies can often expose the key to solving the Problem. Hope to help the people who have met this similar problem.

Java reads Excel exception problems with POI

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.