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)