package org.sky.scientific.excel.handle;

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;

import java.util.Collections;
import java.util.List;

public class MergeCellRangeWriteHandler implements SheetWriteHandler {

	private final List<CellRangeAddress> rangeCellList;

	public MergeCellRangeWriteHandler(List<CellRangeAddress> rangeCellList) {
		this.rangeCellList = (rangeCellList == null) ? Collections.emptyList() : rangeCellList;
	}

	public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
		Sheet sheet = writeSheetHolder.getSheet();
		for (CellRangeAddress cellRangeAddress : this.rangeCellList) {
			sheet.addMergedRegionUnsafe(cellRangeAddress);
		}
	}
}
