package cn.superdesk.uniorder.common.excel.strategy.style;

import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.*;

/**
 * @Description: 设置样式 - 表头&内容
 * @Author: linjinyu
 * @CreateDate: 2022/7/1 3:14 下午
 * @UpdateUser: linjinyu
 * @UpdateDate: 2022/7/1 3:14 下午
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
public class EasyExcelWriteHandlerCellStyleUtils {

    private EasyExcelWriteHandlerCellStyleUtils() {
    }

    public static HorizontalCellStyleStrategy getHorizontalCellStyleStrategy() {

        /**************************************** 表头的策略 start ****************************************/

        // 表头的策略
        WriteCellStyle headWriteCellStyle = new WriteCellStyle();

        // 背景设置为白色
        headWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.index);
        headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
        headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

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

        // 边框 颜色
//        headWriteCellStyle.setBottomBorderColor(IndexedColors.BLACK1.getIndex());
//        headWriteCellStyle.setLeftBorderColor(IndexedColors.BLACK1.getIndex());
//        headWriteCellStyle.setRightBorderColor(IndexedColors.BLACK1.getIndex());
//        headWriteCellStyle.setTopBorderColor(IndexedColors.BLACK1.getIndex());

        // 自动换行
        headWriteCellStyle.setWrapped(true);
        WriteFont headWriteFont = new WriteFont();
        headWriteFont.setBold(true);
        headWriteFont.setFontName("宋体");
        headWriteFont.setFontHeightInPoints((short) 14);
        headWriteCellStyle.setWriteFont(headWriteFont);

        /**************************************** 表头的策略   end ****************************************/

        /**************************************** 内容的策略 start ****************************************/

        // 内容的策略
        WriteCellStyle contentWriteCellStyle = new WriteCellStyle();

        // 这里需要指定 FillPatternType 为FillPatternType.SOLID_FOREGROUND 不然无法显示背景颜色.头默认了 FillPatternType所以可以不指定
        contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);

        // 背景绿色
        contentWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
        contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
        contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

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

        // 边框 颜色
//        contentWriteCellStyle.setBottomBorderColor(IndexedColors.BLACK1.getIndex());
//        contentWriteCellStyle.setLeftBorderColor(IndexedColors.BLACK1.getIndex());
//        contentWriteCellStyle.setRightBorderColor(IndexedColors.BLACK1.getIndex());
//        contentWriteCellStyle.setTopBorderColor(IndexedColors.BLACK1.getIndex());

        // 自动换行
        contentWriteCellStyle.setWrapped(true);

        // 文字
        WriteFont contentWriteFont = new WriteFont();

        // 字体大小
        contentWriteFont.setFontHeightInPoints((short) 12);
        contentWriteFont.setFontName("宋体");
        contentWriteCellStyle.setWriteFont(contentWriteFont);

        /**************************************** 内容的策略   end ****************************************/

        // 这个策略是 表头是表头的样式 内容是内容的样式 其他的策略可以自己实现

        return new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
    }
}
