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();
    }
相关推荐
Hello.Reader18 小时前
Flink 系统内置函数(Built-in Functions)分类、典型用法与选型建议
大数据·flink·excel
彭于晏Yan1 天前
excel导入导出
spring boot·excel
lbb 小魔仙1 天前
Python 读取 Excel 文件:openpyxl 与 pandas 实战对比
python·excel·pandas
徐赛俊1 天前
# Excel 图表自动变色教程(基于控制单元格)
excel
2501_930707781 天前
如何使用C#代码将 Excel 中的图表转换为图片
excel
娃乐呵2 天前
免费的大批量Excel文档大模型处理数据工具
语言模型·大模型·excel·数据处理
Eiceblue2 天前
使用 Python 写入多类型数据至 Excel 文件
开发语言·python·excel
蹦蹦跳跳垂耳兔2 天前
Excel创建组妙用隐藏
excel
开开心心_Every2 天前
无广告干扰:简单好用文字LOGO设计工具
xml·java·网络·数据库·华为od·华为云·excel
CodeCraft Studio3 天前
Excel处理控件Aspose.Cells教程:使用C#在Excel中创建气泡图
信息可视化·c#·excel·aspose·excel api库·excel气泡图·excel组件库