当前位置 : 主页 > 编程语言 > java >

java POI实现Excel单元格数据换行

来源:互联网 收集:自由互联 发布时间:2022-07-04
Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook(); Sheet sheet = wb.createSheet(); Row row = sheet.createRow(2); Cell cell = row.createCell(2); cell.setCellValue("Use \n with word wrap on to create a new line"); CellStyle cs = wb.cr
Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
Sheet sheet = wb.createSheet();

Row row = sheet.createRow(2);
Cell cell = row.createCell(2);
cell.setCellValue("Use \n with word wrap on to create a new line");


CellStyle cs = wb.createCellStyle();
cs.setWrapText(true); //关键
cell.setCellStyle(cs); //单元格应用设置的style
网友评论