I'm trying to write multiline text to excel cells.
cell.setCellValue("line1 \n line2");
But when I open the document, I see only one line until I double-click it for editing, then it becomes two-lined. Why is it so? Thanks
To start a new line of text at any specific point in a cell: Double-click the cell in which you want to enter a line break. Tip: You can also select the cell, and then press F2. In the cell, click the location where you want to break the line, and press Alt + Enter.
Using automatic wrapping To set text to wrap at the end of the cell, right-click on the cell and select Format Cells (or choose Format > Cells from the menu bar, or press Ctrl+1). On the Alignment tab, under Properties, select Wrap text automatically.
You need to set the row height to accomodate two lines of text.
row.setHeightInPoints((2*sheet.getDefaultRowHeightInPoints()));
You need to set the wrap text = true
to get the new line. Try this : Here wb is the Workbook
.
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