package cn.com.countrygarden.bi.main.handler.wcx;

import org.apache.poi.ss.usermodel.*;

import java.util.List;

/**
 * Created by ADMS on 2018/8/3.
 */
public abstract class Export<T> {
    abstract public void createHeader(Workbook workbook, Sheet sheet);
    abstract public void createBody(List<T> data, Workbook workbook, Sheet sheet);

    /**
     * 创建头风格
     *
     * @param workbook
     * @return
     */
    protected CellStyle createHeaderStyle(Workbook workbook) {
        CellStyle headerStyle = workbook.createCellStyle();
        headerStyle.setAlignment(HorizontalAlignment.CENTER);
        headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        headerStyle.setWrapText(true);
        headerStyle.setBorderBottom(BorderStyle.THIN); //下边框
        headerStyle.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        headerStyle.setBorderLeft(BorderStyle.THIN);    //左边框
        headerStyle.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        headerStyle.setBorderTop(BorderStyle.THIN); //上边框
        headerStyle.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        headerStyle.setBorderRight(BorderStyle.THIN);   //右边框
        headerStyle.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        return headerStyle;
    }

    /**
     * 创建体风格
     * @param workbook
     * @return
     */
    protected CellStyle createBodyStyle(Workbook workbook) {
        CellStyle style = workbook.createCellStyle();
        style.setAlignment(HorizontalAlignment.CENTER);
        style.setVerticalAlignment(VerticalAlignment.CENTER);
        style.setWrapText(true);
        style.setBorderBottom(BorderStyle.THIN); //下边框
        style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        style.setBorderLeft(BorderStyle.THIN);//左边框
        style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        style.setBorderTop(BorderStyle.THIN);//上边框
        style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        style.setBorderRight(BorderStyle.THIN);//右边框
        style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        return style;
    }

    /**
     * 创建单元格
     * @param value
     * @param style
     * @param row
     * @param col
     * @param color
     */
    protected void createCell(String value, CellStyle style, Row row, int col, boolean color) {
        Cell cell = row.createCell(col);

        if (color) {
            style.setFillForegroundColor(IndexedColors.RED.getIndex());
            style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        }

        cell.setCellStyle(style);

        if (value != null) {
            cell.setCellValue(value);
        }
    }

  /*  public String change(Object object) {
        if (null == object) {
            return "";
        } else {
            return object + "";
        }
    }*/

   /* public boolean changeColor(Object o1, Object o2) {
        if (null == o1 && null == o2) {
            return false;
        }
        if (null == o1 || null == o2) {
            return true;
        }

        if (o1.equals(o2)) {
            return false;
        }
        return true;
    }*/
}
