package com.cool.store.handler;

import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;

import com.alibaba.excel.write.handler.SheetWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;

/**
 * 第一行 拦截器
 */
public class ImplProgressReportSheetWriteHandler implements SheetWriteHandler {

    private final String title;

    public ImplProgressReportSheetWriteHandler(String title) {
        this.title = title;
    }
    @Override
    public void beforeSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {

    }

    @Override
    public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
        Workbook workbook = writeWorkbookHolder.getWorkbook();
        Sheet sheet = workbook.getSheetAt(0);
        // 设置第一行标题
        Row row1 = sheet.createRow(0);
        row1.setHeight((short) 300);
        Cell row1Cell1 = row1.createCell(0);
        row1Cell1.setCellValue(title);
        CellStyle row1CellStyle = workbook.createCellStyle();
        row1CellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        row1CellStyle.setAlignment(HorizontalAlignment.LEFT);
        Font row1Font = workbook.createFont();
        row1Font.setBold(true);
        row1Font.setFontName("方正小标宋_GBK");
        row1Font.setFontHeightInPoints((short) 10);
        row1CellStyle.setFont(row1Font);
        row1Cell1.setCellStyle(row1CellStyle);
        //合并单元格，起始行,结束行,起始列,结束列
        sheet.addMergedRegionUnsafe(new CellRangeAddress(0, 1, 0, 17));
    }
}