Example usage for org.apache.poi.xssf.usermodel DefaultIndexedColorMap DefaultIndexedColorMap

List of usage examples for org.apache.poi.xssf.usermodel DefaultIndexedColorMap DefaultIndexedColorMap

Introduction

In this page you can find the example usage for org.apache.poi.xssf.usermodel DefaultIndexedColorMap DefaultIndexedColorMap.

Prototype

DefaultIndexedColorMap

Source Link

Usage

From source file:br.com.tecsinapse.dataio.style.TableCellStyle.java

License:LGPL

public CellStyle toCellStyle(Workbook wb) {
    CellStyle cellStyle = wb.createCellStyle();

    final HSSFColor bgColor = getBackgroundColor();
    if (bgColor != null) {
        if (cellStyle instanceof XSSFCellStyle) {
            ((XSSFCellStyle) cellStyle)/*  w  ww  .  j ava 2 s. c o  m*/
                    .setFillForegroundColor(new XSSFColor(toAwtColor(bgColor), new DefaultIndexedColorMap()));
        } else {
            cellStyle.setFillForegroundColor(getBackgroundColor().getIndex());
        }
        cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    }
    if (getBorder() != null) {
        cellStyle = border.toCellStyle(cellStyle);
    }
    if (getVAlign() != null) {
        cellStyle.setVerticalAlignment(vAlign.getCellStyleVAlign());
    }
    if (getHAlign() != null) {
        cellStyle.setAlignment(hAlign.getCellStyleHAlign());
    }

    cellStyle.setWrapText(isWrapText());

    Font font = wb.createFont();
    configFont(font);
    cellStyle.setFont(font);
    if (cellFormat != null && !cellFormat.isEmpty()) {
        cellStyle.setDataFormat(wb.createDataFormat().getFormat(cellFormat));
    }
    return cellStyle;
}