I use Apache POI 3.16 to create an Excel file. I want to set the data inside a particular cell to have a linebreak :
rowConsommationEtRealisation.createCell(0).setCellValue("Consommation (crédits)\r\nRéalisation (produits)");
When I open the file then the cell value does not have linebreak ! So how to create linebreak ?
We will press the excel shortcut key ALT + ENTER to insert the carriage return character in excel cell. As we press the “ALT + ENTER” key, it pushes the content in front of the selected data to the new line by inserting a carriage return.
Double-click on the cell in which you want to insert the line break (or press F2). This will get you into the edit mode in the cell. Place the cursor where you want the line break. Use the keyboard shortcut – ALT + ENTER (hold the ALT key and then press Enter).
In the input box to the right of Other press Ctrl + J to insert a line break as your delimiter. You should see dividers appear in the Data preview pane where there are line breaks in your data. Press the Next button.
We have successfully added hard returns within the cells and we can now apply this tip when entering data into our worksheet. Hard returns come in handy when we want to force line breaks within cells with long text strings or sentences, and it is super easy to do with just one shortcut: Alt + Enter.
Try this: here
Row row = sheet.createRow(2);
Cell cell = row.createCell(2);
cell.setCellValue("Use \n with word wrap on to create a new line");
//to enable newlines you need set a cell styles with wrap=true
CellStyle cs = wb.createCellStyle();
cs.setWrapText(true);
cell.setCellStyle(cs);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With