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

top.zeimao77.product.fileio.oexcel.CellStyleFactory Maven / Gradle / Ivy

package top.zeimao77.product.fileio.oexcel;

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

import java.util.HashMap;
import java.util.Map;

public class CellStyleFactory {

    private Map styleMap = new HashMap<>();

    private Workbook workbook;

    public CellStyleFactory(Workbook workbook) {
        this.workbook = workbook;
    }

    public CellStyle create(String format) {
        CellStyle cellStyle = styleMap.get(format);
        if(cellStyle == null) {
            cellStyle = workbook.createCellStyle();
            DataFormat f = workbook.createDataFormat();
            cellStyle.setDataFormat(f.getFormat(format));
            cellStyle.setAlignment(HorizontalAlignment.RIGHT);
            cellStyle.setVerticalAlignment(VerticalAlignment.BOTTOM);
            styleMap.put(format, cellStyle);
        }
        return cellStyle;
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy