excel 导出 单元格换行

1、使用setWrapText方法来设置单元格的自动换行:style.setWrapText(true);

2、使用\n来表示换行

java 复制代码
import java.io.FileOutputStream;
import java.io.IOException;

public class ExcelExporter {
    public static void main(String[] args) throws IOException {
        // 创建工作簿对象
        XSSFWorkbook workbook = new XSSFWorkbook();

        // 创建工作表对象
        XSSFSheet sheet = workbook.createSheet("Sheet1");

        // 创建行和单元格对象
        XSSFRow row = sheet.createRow(0);
        XSSFCell cell = row.createCell(0);

        // 设置单元格的值和样式
        cell.setCellValue("Hello\nWorld");
        XSSFCellStyle style = workbook.createCellStyle();
        style.setWrapText(true);
        cell.setCellStyle(style);

        // 将工作簿写入文件
        FileOutputStream outputStream = new FileOutputStream("excel1.xlsx");
        workbook.write(outputStream);
        outputStream.close();
    }
相关推荐
开开心心_Every3 小时前
强制打字练习工具:打够百字才可退出
java·游戏·微信·eclipse·pdf·excel·语音识别
开开心心_Every4 小时前
多端免费远程控制工具:4K流畅同账号直连
游戏·macos·微信·pdf·excel·语音识别·phpstorm
hhzz18 小时前
Springboot项目中使用POI操作Excel(详细教程系列3/3)
spring boot·后端·excel·poi·easypoi
Excel工作圈1 天前
凭证助手一键匹配已勾选抵扣发票与全量发票明细
数据库·excel
qq_150841991 天前
32位的CVI2010基于ExcelReport库无法正常访问64位EXCEL的解决方案
excel
weixin_431822401 天前
办公自动化:通过字符串相似度算法找出Excel 中的重复数据
excel·零售
寄思~1 天前
Excel 数据匹配工具 -笔记
笔记·python·学习·excel
222you1 天前
智慧社区:居民信息Excel导入数据库
excel
霍格沃兹测试开发学社测试人社区1 天前
Playwright数据驱动测试:从Excel与JSON获取测试数据指南
excel·playwright
关于不上作者榜就原神启动那件事2 天前
Java中大量数据Excel导入导出的实现方案
java·开发语言·excel