Excel 单元格中的多行文本 [英] Multiline text in Excel cells

查看:27
本文介绍了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()));

您需要设置 wrap text = true 以获取新行.尝试这个 :这里 wb 是 Workbook.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆