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();
    }
相关推荐
小葱炖豆腐10 小时前
python绘制excel折线图
python·excel·numpy·pandas·matplotlib
cspttty21 小时前
2026年财务分析岗JD中的Excel、SQL、BI与业务分析要求
大数据·sql·excel
cspttty21 小时前
HR数字化校招准备路线:Excel、SQL、BI和AI工具怎么学
人工智能·sql·excel
鲲穹AI种草2 天前
Excel 表格批量处理与数据整理,多款表格工具能力客观记录
excel·表格处理
cspttty2 天前
2026秋招供应链分析师技能栈:SQL、Excel、BI与业务分析
数据库·sql·excel
Zzq_Fighting3 天前
Excel批量匹配数据
excel
E_ICEBLUE3 天前
Python 实现 Excel 转 Markdown,支持工作表、单元格区域和批量处理
python·excel·markdown·格式转换
拆房老料3 天前
ONLYOFFICE 集群部署实战:9.3 多实例方案与 9.4 架构变化
开源·word·excel·开源软件·ppt
ms365copilot3 天前
Excel Copilot挖掘数据洞察,不用精通函数也能做数据分析 (1)
数据分析·excel·copilot
babe小鑫3 天前
精算学专业秋招:Excel、SQL、R和Python应该先练什么
sql·r语言·excel