欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【poi第六节】poi操作excel合并单元格,java合并excel单元格

程序员文章站 2022-07-13 14:42:59
...

poi操作excel合并单元格,java合并excel单元格


import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

/**
 * @ClassName 类名:ExcelDemo6
 * @Author作者: hzh
 * @Date时间:2018/12/4 14:56
 * 合并单元格
 **/
public class ExcelDemo6 {

    public static void main(String[] args) throws Exception {
        Workbook wb = new HSSFWorkbook();
        Sheet sheet = wb.createSheet("hi sheet");
        Row row = sheet.createRow(1);
        Cell cell = row.createCell(1);
        cell.setCellValue("测试合并单元格");
        sheet.addMergedRegion(new CellRangeAddress(1, 2, 1, 3));


        FileOutputStream fileOutputStream = new FileOutputStream("D://file//合并.xls");
        wb.write(fileOutputStream);
        wb.close();
    }
}