Example usage for org.apache.poi.xssf.usermodel XSSFCellStyle getFillBackgroundXSSFColor

List of usage examples for org.apache.poi.xssf.usermodel XSSFCellStyle getFillBackgroundXSSFColor

Introduction

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

Prototype

public XSSFColor getFillBackgroundXSSFColor() 

Source Link

Document

Get the background fill color.

Usage

From source file:com.vaadin.addon.spreadsheet.XSSFColorConverter.java

License:Open Source License

@Override
public void colorStyles(CellStyle cellStyle, StringBuilder sb) {
    XSSFCellStyle cs = (XSSFCellStyle) cellStyle;
    XSSFColor fillBackgroundXSSFColor = cs.getFillBackgroundXSSFColor();
    XSSFColor fillForegroundXSSFColor = cs.getFillForegroundXSSFColor();
    String backgroundColor = null;
    if (fillForegroundXSSFColor != null && !fillForegroundXSSFColor.isAuto()) {
        backgroundColor = styleColor(fillForegroundXSSFColor);
    } else if (fillBackgroundXSSFColor != null && !fillBackgroundXSSFColor.isAuto()) {
        backgroundColor = styleColor(fillBackgroundXSSFColor);
    } else {//from   w  ww.  jav  a2 s.c  o  m
        // bypass POI API and try to get the fill ourself, because of bug:
        // https://issues.apache.org/bugzilla/show_bug.cgi?id=53262
        try {
            XSSFColor themeColor = getFillColor(cs);
            if (themeColor != null && !themeColor.isAuto()) {
                backgroundColor = styleColor(themeColor);
            }
        } catch (Exception e) {
            LOGGER.log(Level.FINEST, e.getMessage(), e);
        }
    }

    if (backgroundColor != null && !backgroundColor.equals(defaultBackgroundColor)) {
        sb.append("background-color:");
        sb.append(backgroundColor);
    }

    XSSFColor xssfColor = cs.getFont().getXSSFColor();
    if (xssfColor != null) {
        String color = styleColor(xssfColor);
        if (color != null && !color.equals(defaultColor)) {
            sb.append("color:");
            sb.append(color);
        }
    }
}

From source file:com.vaadin.addon.spreadsheet.XSSFColorConverter.java

License:Open Source License

@Override
public boolean hasBackgroundColor(CellStyle cellStyle) {
    XSSFCellStyle cs = (XSSFCellStyle) cellStyle;
    XSSFColor fillBackgroundXSSFColor = cs.getFillBackgroundXSSFColor();
    XSSFColor fillForegroundXSSFColor = cs.getFillForegroundXSSFColor();
    if (fillForegroundXSSFColor != null && !fillForegroundXSSFColor.isAuto()) {
        return true;
    } else if (fillBackgroundXSSFColor != null && !fillBackgroundXSSFColor.isAuto()) {
        return true;
    } else {//from w w w  .  jav a  2  s. c o  m
        // bypass POI API and try to get the fill ourself, because of bug:
        // https://issues.apache.org/bugzilla/show_bug.cgi?id=53262
        try {
            XSSFColor themeColor = getFillColor(cs);
            if (themeColor != null && !themeColor.isAuto()) {
                return true;
            }
        } catch (Exception e) {
            LOGGER.log(Level.FINEST, e.getMessage(), e);
        }
    }
    return false;
}

From source file:org.bbreak.excella.core.test.util.TestUtil.java

License:Open Source License

private static String getCellStyleString(XSSFCellStyle cellStyle) {
    StringBuffer sb = new StringBuffer();
    if (cellStyle != null) {
        XSSFFont font = cellStyle.getFont();
        sb.append("Font=").append(font.getCTFont()).append(",");
        sb.append("DataFormat=").append(cellStyle.getDataFormat()).append(",");
        sb.append("DataFormatString=").append(cellStyle.getDataFormatString()).append(",");
        sb.append("Hidden=").append(cellStyle.getHidden()).append(",");
        sb.append("Locked=").append(cellStyle.getLocked()).append(",");
        sb.append("Alignment=").append(cellStyle.getAlignmentEnum()).append(",");
        sb.append("WrapText=").append(cellStyle.getWrapText()).append(",");
        sb.append("VerticalAlignment=").append(cellStyle.getVerticalAlignmentEnum()).append(",");
        sb.append("Rotation=").append(cellStyle.getRotation()).append(",");
        sb.append("Indention=").append(cellStyle.getIndention()).append(",");
        sb.append("BorderLeft=").append(cellStyle.getBorderLeftEnum()).append(",");
        sb.append("BorderRight=").append(cellStyle.getBorderRightEnum()).append(",");
        sb.append("BorderTop=").append(cellStyle.getBorderTopEnum()).append(",");
        sb.append("BorderBottom=").append(cellStyle.getBorderBottomEnum()).append(",");

        sb.append("LeftBorderColor=").append(getXSSFColorString(cellStyle.getLeftBorderXSSFColor()))
                .append(",");
        sb.append("RightBorderColor=").append(getXSSFColorString(cellStyle.getRightBorderXSSFColor()))
                .append(",");
        sb.append("TopBorderColor=").append(getXSSFColorString(cellStyle.getTopBorderXSSFColor())).append(",");
        sb.append("BottomBorderColor=").append(getXSSFColorString(cellStyle.getBottomBorderXSSFColor()))
                .append(",");

        sb.append("FillPattern=").append(cellStyle.getFillPatternEnum()).append(",");
        sb.append("FillForegroundColor=").append(getXSSFColorString(cellStyle.getFillForegroundXSSFColor()))
                .append(",");
        sb.append("FillBackgroundColor=").append(getXSSFColorString(cellStyle.getFillBackgroundXSSFColor()));
    }/*from w  ww.  j  a  va  2  s.  c o  m*/
    return sb.toString();
}

From source file:org.bbreak.excella.reports.ReportsTestUtil.java

License:Open Source License

/**
 * XSSF????//  w w w. ja va2  s .  c om
 * 
 * @param cellStyle 
 * @return ??
 */
private static String getCellStyleString(XSSFCellStyle cellStyle) {
    StringBuffer sb = new StringBuffer();
    if (cellStyle != null) {
        XSSFFont font = cellStyle.getFont();
        sb.append("Font=").append(font.getCTFont()).append(",");
        sb.append("DataFormat=").append(cellStyle.getDataFormat()).append(",");
        sb.append("DataFormatString=").append(cellStyle.getDataFormatString()).append(",");
        sb.append("Hidden=").append(cellStyle.getHidden()).append(",");
        sb.append("Locked=").append(cellStyle.getLocked()).append(",");
        sb.append("Alignment=").append(cellStyle.getAlignmentEnum()).append(",");
        sb.append("WrapText=").append(cellStyle.getWrapText()).append(",");
        sb.append("VerticalAlignment=").append(cellStyle.getVerticalAlignmentEnum()).append(",");
        sb.append("Rotation=").append(cellStyle.getRotation()).append(",");
        sb.append("Indention=").append(cellStyle.getIndention()).append(",");
        sb.append("BorderLeft=").append(cellStyle.getBorderLeftEnum()).append(",");
        sb.append("BorderRight=").append(cellStyle.getBorderRightEnum()).append(",");
        sb.append("BorderTop=").append(cellStyle.getBorderTopEnum()).append(",");
        sb.append("BorderBottom=").append(cellStyle.getBorderBottomEnum()).append(",");

        sb.append("LeftBorderColor=").append(getXSSFColorString(cellStyle.getLeftBorderXSSFColor()))
                .append(",");
        sb.append("RightBorderColor=").append(getXSSFColorString(cellStyle.getRightBorderXSSFColor()))
                .append(",");
        sb.append("TopBorderColor=").append(getXSSFColorString(cellStyle.getTopBorderXSSFColor())).append(",");
        sb.append("BottomBorderColor=").append(getXSSFColorString(cellStyle.getBottomBorderXSSFColor()))
                .append(",");

        sb.append("FillPattern=").append(cellStyle.getFillPatternEnum()).append(",");
        try {
            sb.append("FillForegroundColor=").append(getXSSFColorString(cellStyle.getFillForegroundXSSFColor()))
                    .append(",");
        } catch (NullPointerException e) {
            // POI-3.7???
            sb.append("FillForegroundColor=none,");
        }

        try {
            sb.append("FillBackgroundColor=")
                    .append(getXSSFColorString(cellStyle.getFillBackgroundXSSFColor()));
        } catch (NullPointerException e) {
            // POI-3.7???
            sb.append("FillBackgroundColor=none,");
        }
    }
    return sb.toString();
}