All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.eworkcloud.excel.style.ExportStyle Maven / Gradle / Ivy

There is a newer version: 2.6.0
Show newest version
package com.eworkcloud.excel.style;

import com.eworkcloud.excel.model.ExcelColumn;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.util.ObjectUtils;

public interface ExportStyle {
    /**
     * 标题样式
     *
     * @param workbook 工作簿
     * @return 样式
     */
    CellStyle titleStyle(Workbook workbook);

    /**
     * 表头样式
     *
     * @param workbook 工作簿
     * @param required 必须项
     * @return 样式
     */
    CellStyle headerStyle(Workbook workbook, boolean required);

    /**
     * 左对齐
     *
     * @param workbook 工作簿
     * @param isWrap   换行
     * @return 样式
     */
    CellStyle alignLeft(Workbook workbook, boolean isWrap);

    /**
     * 右对齐
     *
     * @param workbook 工作簿
     * @param isWrap   换行
     * @return 样式
     */
    CellStyle alignRight(Workbook workbook, boolean isWrap);

    /**
     * 居中对齐
     *
     * @param workbook 工作簿
     * @param isWrap   换行
     * @return 样式
     */
    CellStyle alignCenter(Workbook workbook, boolean isWrap);

    /**
     * 获取样式
     *
     * @param workbook 工作簿
     * @param column   列配置
     * @return 样式
     */
    default CellStyle getCellStyle(Workbook workbook, ExcelColumn column) {
        Class clazz = column.getField().getType();
        if (!ObjectUtils.isEmpty(column.getReplace())) {
            return alignCenter(workbook, column.isWrap());
        } else if (clazz == Boolean.class || clazz == Boolean.TYPE) {
            return alignCenter(workbook, column.isWrap());
        } else if (clazz == Byte.class || clazz == Byte.TYPE) {
            return alignCenter(workbook, column.isWrap());
        } else if (clazz == Character.class || clazz == Character.TYPE) {
            return alignCenter(workbook, column.isWrap());
        } else if (clazz == Short.class || clazz == Short.TYPE) {
            return alignRight(workbook, column.isWrap());
        } else if (clazz == Integer.class || clazz == Integer.TYPE) {
            return alignRight(workbook, column.isWrap());
        } else if (clazz == Long.class || clazz == Long.TYPE) {
            return alignRight(workbook, column.isWrap());
        } else if (clazz == Float.class || clazz == Float.TYPE) {
            return alignRight(workbook, column.isWrap());
        } else if (clazz == Double.class || clazz == Double.TYPE) {
            return alignRight(workbook, column.isWrap());
        } else if (clazz == java.math.BigInteger.class) {
            return alignRight(workbook, column.isWrap());
        } else if (clazz == java.math.BigDecimal.class) {
            return alignRight(workbook, column.isWrap());
        } else if (clazz == java.util.Date.class) {
            return alignCenter(workbook, column.isWrap());
        } else if (clazz == java.sql.Date.class) {
            return alignCenter(workbook, column.isWrap());
        } else if (clazz == java.sql.Time.class) {
            return alignCenter(workbook, column.isWrap());
        } else if (clazz == java.sql.Timestamp.class) {
            return alignCenter(workbook, column.isWrap());
        } else if (clazz == java.time.LocalDate.class) {
            return alignCenter(workbook, column.isWrap());
        } else if (clazz == java.time.LocalTime.class) {
            return alignCenter(workbook, column.isWrap());
        } else if (clazz == java.time.LocalDateTime.class) {
            return alignCenter(workbook, column.isWrap());
        } else {
            return alignLeft(workbook, column.isWrap());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy