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();
    }
相关推荐
wtsolutions几秒前
JSON to Excel Add-in - Seamless Integration Within Excel
json·excel
wtsolutions11 分钟前
Getting Started with JSON to Excel Web App - Convert in Seconds
json·excel·web app
wtsolutions4 小时前
Using the JSON to Excel API - Programmatic Access for Developers
json·excel
qq_435139574 小时前
EasyExcel(FastExcel)Excel导出功能 技术文档
excel
wtsolutions7 小时前
Understanding JSON Formats - What JSON to Excel Supports
json·excel
wtsolutions7 小时前
Advanced Features - Unlocking the Power of JSON to Excel Pro
linux·json·excel
fs哆哆9 小时前
VB.NET和VBA教程-如何查找Excel数据区域边界
excel
小矮强9 小时前
Excel中根据年月日提取月日,并按月日进行排序
excel
开开心心_Every9 小时前
图片批量压缩工具:支持有损无损两种模式
python·游戏·微信·django·pdf·excel·语音识别
wtsolutions10 小时前
Real-World Use Cases - How Organizations Use JSON to Excel
json·excel