package cn.iocoder.yudao.module.server.controller.admin.harmfulinforeport;

import com.alibaba.excel.write.handler.SheetWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress;

public class SummaryExcelMergeHandler implements SheetWriteHandler {

    @Override
    public void beforeSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {}

    @Override
    public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
        Sheet sheet = writeSheetHolder.getSheet();

        // 合并 A1:D1 -> “盟市”
//        sheet.addMergedRegionUnsafe(new CellRangeAddress(0, 0, 0, 3));
//        // 合并 E1:H1 -> “部门”
//        sheet.addMergedRegionUnsafe(new CellRangeAddress(0, 0, 4, 7));

        // 第一行合并
        // 合并 B1:D1 -> "盟市"
        sheet.addMergedRegionUnsafe(new CellRangeAddress(0, 0, 1, 3));
        // 合并 F1:H1 -> "部门"
        sheet.addMergedRegionUnsafe(new CellRangeAddress(0, 0, 5, 7));

        // 最后一行合并 (全年共计)
        // 合并 A7:H7
        //sheet.addMergedRegionUnsafe(new CellRangeAddress(6, 6, 0, 7));

        // 新增合并
        // 合并 A1-A2 (第一列，第1行到第2行)
        sheet.addMergedRegionUnsafe(new CellRangeAddress(0, 1, 0, 0));

        // 合并 E1-E6 (第五列，第1行到第6行)
        sheet.addMergedRegionUnsafe(new CellRangeAddress(0, 6, 4, 4));


    }
}
