POIStyleUtil.java 1.28 KB
Newer Older
frank.xa.zhang's avatar
frank.xa.zhang committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
package pwc.taxtech.atms.common.util;

import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/**
 * author kevin
 * version 1.0
 */
public class POIStyleUtil {

    public static void setCellAlign(XSSFWorkbook xssfWorkbook, Cell cell) {
        CellStyle cellStyle = xssfWorkbook.createCellStyle();
        cellStyle.setAlignment(HorizontalAlignment.CENTER);// 设置居中
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        cell.setCellStyle(cellStyle);
    }

    ///new XSSFColor(java.awt.Color.YELLOW)
    public static void setCellBackgroundColor(XSSFWorkbook xssfWorkbook, Cell cell,   XSSFColor xssfColor ,FillPatternType fillPatternType) {
        if(fillPatternType == null)
            fillPatternType = FillPatternType.SOLID_FOREGROUND;
        XSSFCellStyle cellStyle = xssfWorkbook.createCellStyle();
        cellStyle.setFillPattern(fillPatternType);
        cellStyle.setFillForegroundColor(xssfColor);
        cell.setCellStyle(cellStyle);
    }
    public static void setCellBackgroundColor(XSSFWorkbook xssfWorkbook, Cell cell,   XSSFColor xssfColor){
        setCellBackgroundColor(xssfWorkbook, cell, xssfColor, null);
    }
}