在Excel单元格多行文本 [英] Multiline text in Excel cells
本文介绍了在Excel单元格多行文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试着写多行文本到Excel单元格。
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
推荐答案
您需要设置行的高度以容纳两行文本。
You need to set the row height to accomodate two lines of text.
row.setHeightInPoints((2*sheet.getDefaultRowHeightInPoints()));
您需要设置文本换行= TRUE
来获得新的行。
尝试这个 :
这里WB是工作簿
。
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);
这篇关于在Excel单元格多行文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文