Example usage for org.apache.poi.ss.usermodel CellStyle setFillPattern

List of usage examples for org.apache.poi.ss.usermodel CellStyle setFillPattern

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel CellStyle setFillPattern.

Prototype

void setFillPattern(FillPatternType fp);

Source Link

Document

setting to one fills the cell with the foreground color...

Usage

From source file:com.ferid.app.classroom.utility.ExcelStyleManager.java

License:Apache License

/**
 * Header cell style (dates)//from   w  w w .j  a v a 2s  . c o m
 * @param wb Workbook
 * @return CellStyle
 */
public static CellStyle getHeaderCellStyle(Workbook wb) {
    CellStyle cellStyle = wb.createCellStyle();

    cellStyle.setAlignment(HorizontalAlignment.CENTER);

    Font font = wb.createFont();
    font.setFontHeightInPoints((short) 8);
    font.setBold(true);
    cellStyle.setFont(font);

    cellStyle.setWrapText(true);

    cellStyle.setFillForegroundColor(IndexedColors.LIGHT_TURQUOISE.getIndex());
    cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

    cellStyle.setBorderRight(BorderStyle.THIN);
    cellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
    cellStyle.setBorderBottom(BorderStyle.THIN);
    cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
    cellStyle.setBorderLeft(BorderStyle.THIN);
    cellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
    cellStyle.setBorderTop(BorderStyle.THIN);
    cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());

    return cellStyle;
}

From source file:com.ferid.app.classroom.utility.ExcelStyleManager.java

License:Apache License

/**
 * Content cell style (presence)//w ww. j a v  a  2 s  .c o  m
 * @param wb Workbook
 * @return CellStyle
 */
public static CellStyle getContentCellStyle(Workbook wb) {
    CellStyle cellStyle = wb.createCellStyle();

    cellStyle.setAlignment(HorizontalAlignment.CENTER);

    Font font = wb.createFont();
    font.setFontHeightInPoints((short) 8);
    cellStyle.setFont(font);

    cellStyle.setWrapText(true);

    cellStyle.setFillForegroundColor(IndexedColors.LIGHT_YELLOW.getIndex());
    cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

    cellStyle.setBorderRight(BorderStyle.THIN);
    cellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
    cellStyle.setBorderBottom(BorderStyle.THIN);
    cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
    cellStyle.setBorderLeft(BorderStyle.THIN);
    cellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
    cellStyle.setBorderTop(BorderStyle.THIN);
    cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());

    return cellStyle;
}

From source file:com.firstonesoft.poi.TimesheetDemo.java

License:Apache License

/**
 * Create a library of cell styles/*from   w ww.  j  ava 2s .  co  m*/
 */
private static Map<String, CellStyle> createStyles(Workbook wb) {
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();

    CellStyle style;

    Font titleFont = wb.createFont();
    titleFont.setFontHeightInPoints((short) 18);
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFont(titleFont);
    styles.put("title", style);

    Font monthFont = wb.createFont();
    monthFont.setFontHeightInPoints((short) 11);
    monthFont.setColor(IndexedColors.WHITE.getIndex());
    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFont(monthFont);
    style.setWrapText(true);
    styles.put("header", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setWrapText(true);
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setRightBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderTop(CellStyle.BORDER_THIN);
    style.setTopBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
    styles.put("cell", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setDataFormat(wb.createDataFormat().getFormat("0.00"));
    styles.put("formula", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setDataFormat(wb.createDataFormat().getFormat("0.00"));
    styles.put("formula_2", style);

    return styles;
}

From source file:com.funtl.framework.smoke.core.commons.excel.ExportExcel.java

License:Apache License

/**
 * ?/*from  w  ww. j  av  a2s. com*/
 *
 * @param wb 
 * @return ?
 */
private Map<String, CellStyle> createStyles(Workbook wb) {
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();

    CellStyle style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.CENTER);
    //      style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(VerticalAlignment.CENTER);
    //      style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    Font titleFont = wb.createFont();
    titleFont.setFontName("Arial");
    titleFont.setFontHeightInPoints((short) 16);
    titleFont.setBold(true);
    //      titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style.setFont(titleFont);
    styles.put("title", style);

    style = wb.createCellStyle();
    style.setVerticalAlignment(VerticalAlignment.CENTER);
    //      style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setBorderRight(BorderStyle.THIN);
    //      style.setBorderRight(CellStyle.BORDER_THIN);
    style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setBorderLeft(BorderStyle.THIN);
    //      style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setBorderTop(BorderStyle.THIN);
    //      style.setBorderTop(CellStyle.BORDER_THIN);
    style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setBorderBottom(BorderStyle.THIN);
    //      style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    Font dataFont = wb.createFont();
    dataFont.setFontName("Arial");
    dataFont.setFontHeightInPoints((short) 10);
    style.setFont(dataFont);
    styles.put("data", style);

    style = wb.createCellStyle();
    style.cloneStyleFrom(styles.get("data"));
    style.setAlignment(HorizontalAlignment.LEFT);
    //      style.setAlignment(CellStyle.ALIGN_LEFT);
    styles.put("data1", style);

    style = wb.createCellStyle();
    style.cloneStyleFrom(styles.get("data"));
    style.setAlignment(HorizontalAlignment.CENTER);
    //      style.setAlignment(CellStyle.ALIGN_CENTER);
    styles.put("data2", style);

    style = wb.createCellStyle();
    style.cloneStyleFrom(styles.get("data"));
    style.setAlignment(HorizontalAlignment.RIGHT);
    //      style.setAlignment(CellStyle.ALIGN_RIGHT);
    styles.put("data3", style);

    style = wb.createCellStyle();
    style.cloneStyleFrom(styles.get("data"));
    //      style.setWrapText(true);
    style.setAlignment(HorizontalAlignment.CENTER);
    //      style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    //      style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    Font headerFont = wb.createFont();
    headerFont.setFontName("Arial");
    headerFont.setFontHeightInPoints((short) 10);
    headerFont.setBold(true);
    //      headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    headerFont.setColor(IndexedColors.WHITE.getIndex());
    style.setFont(headerFont);
    styles.put("header", style);

    return styles;
}

From source file:com.github.cutstock.excel.model.SheetBuilder.java

License:Apache License

private void initStyles() {
    CellStyle style;
    Workbook wb = sheet.getWorkbook();/*from w  ww . ja v a 2s. c o m*/

    Font titleFont = wb.createFont();
    titleFont.setFontHeightInPoints((short) 18);
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFont(titleFont);
    styles.put("title", style);

    Font subTitle = wb.createFont();
    subTitle.setFontHeightInPoints((short) 12);
    subTitle.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFont(subTitle);
    styles.put("header", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setRightBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderTop(CellStyle.BORDER_THIN);
    style.setTopBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
    styles.put("cell", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setRightBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderTop(CellStyle.BORDER_THIN);
    style.setTopBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
    styles.put("highCell", style);

    style = wb.createCellStyle();
    Font imageTitle = wb.createFont();
    imageTitle.setFontHeightInPoints((short) 200);
    style.setFont(imageTitle);
    styles.put("image", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setDataFormat(wb.createDataFormat().getFormat("0.00"));
    styles.put("formula_2", style);

}

From source file:com.github.jferard.spreadsheetwrapper.xls.poi.XlsPoiStyleHelper.java

License:Open Source License

/**
 * @param workbook/* w w  w .j a va 2  s.  com*/
 *            workbook for conversion
 * @param wrapperCellStyle
 *            the cell style
 * @return the internal cell style
 */
public CellStyle toCellStyle(final Workbook workbook, final WrapperCellStyle wrapperCellStyle) {
    final CellStyle cellStyle = workbook.createCellStyle();
    final Font font = this.fontHelper.toCellFont(workbook, wrapperCellStyle);
    cellStyle.setFont(font);

    final WrapperColor backgroundColor = wrapperCellStyle.getBackgroundColor();

    if (backgroundColor != null) {
        final HSSFColor hssfColor = this.colorHelper.toHSSFColor(backgroundColor);

        final short index = hssfColor.getIndex();
        cellStyle.setFillForegroundColor(index);
        cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    }

    this.borderHelper.setCellBorders(wrapperCellStyle, cellStyle);
    return cellStyle;
}

From source file:com.github.luischavez.lat.excel.Excel.java

License:Open Source License

protected void setContent(Workbook workbook, Sheet sheet, String groupName) {
    CellStyle style = workbook.createCellStyle();
    Font font = workbook.createFont();
    font.setColor(HSSFColor.WHITE.index);
    style.setFont(font);//from w  w  w.  ja va2 s.  com
    style.setFillBackgroundColor(IndexedColors.GREEN.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);

    Row row = sheet.createRow(0);
    this.createCell(0, row, style, "#");
    this.createCell(1, row, style, "Matricula");
    this.createCell(2, row, style, "Nombres");
    this.createCell(3, row, style, "Apellidos");
    for (int i = 0; i < 6; i++) {
        this.createCell(4 + i, row, style, "Practica #" + (i + 1));
    }
    this.createCell(10, row, style, "Promedio");

    int current = 1;
    RowList students = this.studentController.getByGroup(groupName);
    long groupId = this.groupController.getGroupId(groupName);
    for (com.github.luischavez.database.link.Row student : students) {
        long studentId = student.value("student_id", Long.class);
        String credential = student.value("credential", String.class);
        String firstName = student.value("first_name", String.class);
        String lastName = student.value("last_name", String.class);
        row = sheet.createRow(current);
        this.createNumber(0, row, null, current++);
        this.createCell(1, row, null, credential);
        this.createCell(2, row, null, firstName);
        this.createCell(3, row, null, lastName);
        for (int i = 0; i < 6; i++) {
            double qualification = this.qualificationController.get(groupId, studentId, i + 1);
            if (0 > qualification) {
                qualification = 0;
            }
            this.createNumber(4 + i, row, null, qualification);
        }
        this.createFormula(10, row, style, String.format("AVERAGE(E%d:J%d)", current, current));
    }
    row = sheet.createRow(current);
    this.createFormula(10, row, style, String.format("AVERAGE(K%d:K%d)", 2, current));
}

From source file:com.github.svrtm.xlreport.CellStyle_p.java

License:Apache License

public void copyTo(final CellStyle poiStyle) {
    if (verticalAlignment != null)
        poiStyle.setVerticalAlignment(verticalAlignment);
    if (alignment != null)
        poiStyle.setAlignment(alignment);

    if (borderBottom != null)
        poiStyle.setBorderBottom(borderBottom);
    if (bottomBorderColor != null)
        poiStyle.setBottomBorderColor(bottomBorderColor);
    if (borderLeft != null)
        poiStyle.setBorderLeft(borderLeft);
    if (leftBorderColor != null)
        poiStyle.setLeftBorderColor(leftBorderColor);
    if (borderRight != null)
        poiStyle.setBorderRight(borderRight);
    if (rightBorderColor != null)
        poiStyle.setRightBorderColor(rightBorderColor);
    if (borderTop != null)
        poiStyle.setBorderTop(borderTop);
    if (topBorderColor != null)
        poiStyle.setTopBorderColor(topBorderColor);

    if (wrapText != null)
        poiStyle.setWrapText(wrapText);/*from ww w  . j a v  a2 s.c o m*/

    if (fillPattern != null)
        poiStyle.setFillPattern(fillPattern);
    if (xssfFgColor == null) {
        if (fillForegroundColor != null)
            poiStyle.setFillForegroundColor(fillForegroundColor);
    } else
        ((XSSFCellStyle) poiStyle).setFillForegroundColor(xssfFgColor);

    if (fmt != null)
        poiStyle.setDataFormat(fmt);
}

From source file:com.globalsight.everest.qachecks.DITAQAChecker.java

License:Apache License

private CellStyle getHeaderStyle(Workbook p_workbook) throws Exception {
    if (headerStyle == null) {
        Font font = p_workbook.createFont();
        font.setBoldweight(Font.BOLDWEIGHT_BOLD);
        font.setColor(IndexedColors.BLACK.getIndex());
        font.setUnderline(Font.U_NONE);
        font.setFontName("Times");
        font.setFontHeightInPoints((short) 11);

        CellStyle cs = p_workbook.createCellStyle();
        cs.setFont(font);// w w w.  j a v  a 2 s. c om
        cs.setWrapText(true);
        cs.setFillPattern(CellStyle.SOLID_FOREGROUND);
        cs.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        cs.setBorderTop(CellStyle.BORDER_THIN);
        cs.setBorderRight(CellStyle.BORDER_THIN);
        cs.setBorderBottom(CellStyle.BORDER_THIN);
        cs.setBorderLeft(CellStyle.BORDER_THIN);

        headerStyle = cs;
    }

    return headerStyle;
}

From source file:com.globalsight.everest.qachecks.QAChecker.java

License:Apache License

private CellStyle getHeaderStyle(Workbook p_workbook) {
    if (m_headerStyle == null) {
        Font font = p_workbook.createFont();
        font.setBoldweight(Font.BOLDWEIGHT_BOLD);
        font.setColor(IndexedColors.BLACK.getIndex());
        font.setUnderline(Font.U_NONE);
        font.setFontName("Times");
        font.setFontHeightInPoints((short) 11);

        CellStyle cs = p_workbook.createCellStyle();
        cs.setFont(font);//from   www  .  j  ava  2  s.  c om
        cs.setWrapText(true);
        cs.setFillPattern(CellStyle.SOLID_FOREGROUND);
        cs.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        cs.setBorderTop(CellStyle.BORDER_THIN);
        cs.setBorderRight(CellStyle.BORDER_THIN);
        cs.setBorderBottom(CellStyle.BORDER_THIN);
        cs.setBorderLeft(CellStyle.BORDER_THIN);

        m_headerStyle = cs;
    }

    return m_headerStyle;
}