Poi reads Excel content formatting

Source: Internet
Author: User

When you read Excel content with a poi, you often encounter data formatting problems.

For example: The number 12365 will change to 12365.0, the string number 123 will also become 123.0, and even be turned into a scientific notation. In addition, date formatting is also a headache. In fact, the most desirable way is what Excel is, that poi out of what is, do not engage in any conversion.

After collecting various formats online, find the most satisfying one:

ImportOrg.apache.poi.hssf.usermodel.HSSFDataFormatter;ImportOrg.apache.poi.hssf.usermodel.HSSFDateUtil; PublicObject getValue (cell cell) {if(Cell = =NULL)        return""; //if it is a date type (POI will turn the date to a number)    if(Cell.getcelltype () = =cell. Cell_type_numeric) {//Check If a cell contains a date        if(hssfdateutil.iscelldateformatted (cell)) {Date D=hssfdateutil.getjavadate (Cell.getnumericcellvalue ()); return NewSimpleDateFormat ("Yyyy-mm-dd"). Format (d); }} hssfdataformatter DF=NewHssfdataformatter (); returnDf.formatcellvalue (cell);}

That way, the data will be all the same.

Poi reads Excel content formatting

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.