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

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

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

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.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;

public class DefaultStyle implements ExportStyle {

    @Override
    public CellStyle titleStyle(Workbook workbook) {
        Font font = workbook.createFont();
        font.setFontName("Arial");
        font.setFontHeightInPoints((short) 13);
        font.setBold(true);

        CellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setAlignment(HorizontalAlignment.CENTER);
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle.setWrapText(true);
        cellStyle.setFont(font);
        return cellStyle;
    }

    @Override
    public CellStyle headerStyle(Workbook workbook, boolean required) {
        Font font = workbook.createFont();
        font.setFontName("Arial");
        font.setFontHeightInPoints((short) 11);
        font.setBold(true);
        if (required) {
            font.setColor(Font.COLOR_RED);
        }

        CellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setAlignment(HorizontalAlignment.CENTER);
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle.setWrapText(true);
        cellStyle.setFont(font);
        return cellStyle;
    }

    @Override
    public CellStyle alignLeft(Workbook workbook, boolean isWrap) {
        Font font = workbook.createFont();
        font.setFontName("Arial");
        font.setFontHeightInPoints((short) 11);

        CellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setAlignment(HorizontalAlignment.LEFT);
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle.setWrapText(isWrap);
        cellStyle.setFont(font);
        return cellStyle;
    }

    @Override
    public CellStyle alignRight(Workbook workbook, boolean isWrap) {
        Font font = workbook.createFont();
        font.setFontName("Arial");
        font.setFontHeightInPoints((short) 11);

        CellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setAlignment(HorizontalAlignment.RIGHT);
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle.setWrapText(isWrap);
        cellStyle.setFont(font);
        return cellStyle;
    }

    @Override
    public CellStyle alignCenter(Workbook workbook, boolean isWrap) {
        Font font = workbook.createFont();
        font.setFontName("Arial");
        font.setFontHeightInPoints((short) 11);

        CellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setAlignment(HorizontalAlignment.CENTER);
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle.setWrapText(isWrap);
        cellStyle.setFont(font);
        return cellStyle;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy