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

import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.handler.context.CellWriteHandlerContext;
import org.apache.poi.ss.usermodel.*;

public class SummaryExcelCellStyleHandler implements CellWriteHandler {

    @Override
    public void afterCellDispose(CellWriteHandlerContext context) {
        Cell cell = context.getCell();
        int rowIndex = cell.getRowIndex();

        Sheet sheet = cell.getSheet();
        Workbook workbook = sheet.getWorkbook();
        CellStyle style = workbook.createCellStyle();

        // 边框
        style.setBorderTop(BorderStyle.THIN);
        style.setBorderBottom(BorderStyle.THIN);
        style.setBorderLeft(BorderStyle.THIN);
        style.setBorderRight(BorderStyle.THIN);

        // 对齐
        style.setAlignment(HorizontalAlignment.CENTER);
        style.setVerticalAlignment(VerticalAlignment.CENTER);

        // 字体
        Font font = workbook.createFont();
        font.setFontHeightInPoints((short) 12);
        if (rowIndex == 0 || rowIndex == 1) {
            font.setBold(true);
        }
        style.setFont(font);

        cell.setCellStyle(style);

        // 行高（仅前两行）
        if (rowIndex == 0 || rowIndex == 1) {
            Row row = sheet.getRow(rowIndex);
            if (row != null) {
                row.setHeightInPoints(25);
            }
        }
    }
}
