Java uses POI to generate Excel to force line breaks

Source: Internet
Author: User

A while ago in a school scheduling system, there is a place to use the curriculum generated Excel to export to the customer, because the previous use of Excel is simply a simple application, in the cell is the use of automatic line, and this time may need to use to manually force a newline.
So I found on the Internet, the article found on the Internet is to say in the text in Excel plus/n,/n/r,/r/n and so on, anyway, all kinds of have, and even more strange is that some people say in the cell plus <br>
Later I tried to use the/R after the effect is generated in the file, you use the open, and will not wrap, if you use the mouse in the cell after a click on the line will be automatically wrapped.

Then I thought about it and could do it the following way,
1. First use the POI style in the cells that need to be forced to wrap, and set the style to wrap

Hssfcellstyle cellstyle=Workbook.createcellstyle ();       Cellstyle.setwraptext (true);       Cell.setcellstyle (CellStyle);  

2. Next, in the cells that need to be forced to wrap, use/to force a newline

Hssfcell cell = Row.createcell ((short) 0);    Cell.setcellstyle (CellStyle);                          
Cell.setcellvalue (
New

This makes it possible to force a line break,
The effect of line break is to force a line break in the cell.

// Hello    // world!  

Java uses POI to generate Excel to force line breaks

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.