When exporting Excel with POI, longer numbers don't want to be automatically resolved by scientific notation (GO)

Source: Internet
Author: User

Have done many times to export Excel. Have encountered a problem, if the content contains a relatively long number, such as the order number "2546541656596", Excel will automatically become the scientific counting method ...
Did not solve several times, and recently also exported Excel, determined to find a solution
In Excel, the longer numbers are automatically turned into scientific notation unless we set the cell format to "text"
Haha, seems to find the idea: Use the POI first set the cell to "text-type" on it.
This method is found in the document hssfcell.setcelltype (int type), how to see this method can be set cell format.
Add Cell.setcelltype (hssfcell.cell_type_string) to the code, or no change ...
Once again in a state of helplessness
Searched for half a day from Google and found this article
http://javacrazyer.iteye.com/blog/894758, bloggers write very detailed, from the principle to the solution has been
The idea is still the same, format the cell as "text type"
The following is a direct explanation of the real solution:

1//Create workbook
2 Hssfworkbook wb = new Hssfworkbook ();
3//Create a style
4 Hssfcellstyle CellStyle = Wb.createcellstyle ();
5//Create a DataFormat object
6 Hssfdataformat format = Wb.createdataformat ();
7//In order to really control the cell format, @ refers to the text type, the specific format of the definition or refer to the original text it
8 Cellstyle.setdataformat (Format.getformat ("@"));
9
10//Specific How to create a cell is omitted, and the format of the cell is then written like this
Cell.setcellstyle (CellStyle);

Original address:

When you export Excel with a POI, the longer numbers don't want to be automatically turned into scientific notation. How POI works with Excel "Focus: How to set the cell format to text format" POI set Excel cell format to text, decimal, percent, currency, date, scientific notation, and Chinese capitalization

When exporting Excel with POI, longer numbers don't want to be automatically resolved by scientific notation (GO)

Related Article

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.