本文概述
- 单元示例中的Apache POI换行符
单元示例中的Apache POI换行符
package poiexample;
import java.io.FileOutputStream;
import java.io.OutputStream;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
public class NewlineExample {
public static void main(String[] args) {
try (OutputStream fileOut = new FileOutputStream("srcmini.xls")) {
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet("Sheet");
Row row= sheet.createRow(1);
Cell cell= row.createCell(1);
cell.setCellValue("This is first line and \n this is second line");
CellStyle cs = wb.createCellStyle();
cs.setWrapText(true);
cell.setCellStyle(cs);
row.setHeightInPoints((2*sheet.getDefaultRowHeightInPoints()));
sheet.autoSizeColumn(2);
wb.write(fileOut);
}catch(Exception e) {
System.out.println(e.getMessage());
}
}
}
【apache poi单元格中的换行】输出:
文章图片
推荐阅读
- apache poi概述
- apache poi excel图片
- apache poi绘制形状
- apache poi excel单元格类型
- apache poi单元多种风格
- apache poi绘制边界
- apache poi excel单元格属性
- apache poi隐藏行
- apache poi excel文档标题