alibaba / easyexcel

快速、简洁、解决大文件内存溢出的java处理Excel工具
https://easyexcel.opensource.alibaba.com
Apache License 2.0
32.09k stars 7.5k forks source link

自定义excel导出 怎么让单元格内的内容强制换行,使用\n后,导出的文件单元格必须获得鼠标焦点后才换行,有没有方法导出之后鼠标不聚焦就是换行的 #4011

Closed softlg closed 6 days ago

softlg commented 6 days ago

Demo: (由于业务需求,需要根据动态表头导出, 使用的是自定义的excel导出)

private void export() {
    // 这里自定义设置head信息
    List<List<String>> head = new ArrayList<>();
    // 这里自定义设置head信息
    List<List<Object>> data = new ArrayList<>();

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    EasyExcel.write(outputStream)
            .head(head)
            .sheet()
            .doWrite(data);
   // 其它业务操作
 }

目前效果: image

softlg commented 6 days ago
    // 内容样式
    WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
    // 设置自动换行,前提内容中需要加「\n」才有效
    contentWriteCellStyle.setWrapped(true);
    HorizontalCellStyleStrategy horizontalCellStyleStrategy =
            new HorizontalCellStyleStrategy(null, contentWriteCellStyle);