Example usage for org.apache.poi.xssf.usermodel XSSFColor isAuto

List of usage examples for org.apache.poi.xssf.usermodel XSSFColor isAuto

Introduction

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

Prototype

@Override
public boolean isAuto() 

Source Link

Document

A boolean value indicating the ctColor is automatic and system ctColor dependent.

Usage

From source file:cc.landking.converter.office.excel.XSSFHtmlHelper.java

License:Apache License

private void styleColor(Formatter out, String attr, XSSFColor color) {
    if (color == null || color.isAuto())
        return;//  w w w .ja v a 2 s. co  m

    byte[] rgb = color.getRgb();
    if (rgb == null) {
        return;
    }

    // This is done twice -- rgba is new with CSS 3, and browser that don't
    // support it will ignore the rgba specification and stick with the
    // solid color, which is declared first
    out.format("  %s: #%02x%02x%02x;%n", attr, rgb[0], rgb[1], rgb[2]);
    byte[] argb = color.getARgb();
    if (argb == null) {
        return;
    }
    out.format("  %s: rgba(0x%02x, 0x%02x, 0x%02x, 0x%02x);%n", attr, argb[3], argb[0], argb[1], argb[2]);
}

From source file:com.aiutil.report.utils.XSSFHtmlHelper.java

License:Apache License

private void styleColor(Formatter out, String attr, XSSFColor color) {
    if (color == null || color.isAuto()) {
        return;// ww w  .  ja  va2s .  c  o m
    }

    byte[] rgb = color.getRGB();
    if (rgb == null) {
        return;
    }

    // This is done twice -- rgba is new with CSS 3, and browser that don't
    // support it will ignore the rgba specification and stick with the
    // solid color, which is declared first
    out.format("  %s: #%02x%02x%02x;%n", attr, rgb[0], rgb[1], rgb[2]);
    byte[] argb = color.getARGB();
    if (argb == null) {
        return;
    }
    out.format("  %s: rgba(0x%02x, 0x%02x, 0x%02x, 0x%02x);%n", attr, argb[3], argb[0], argb[1], argb[2]);
}

From source file:com.canoo.webtest.plugins.exceltest.ExcelColorUtils.java

License:Open Source License

public static String getColorName(final AbstractExcelStep step, final Color color) {
    if (color == null) {
        return "none";
    }/*w  w w .ja  v  a 2  s .  c  o  m*/
    if (color instanceof HSSFColor) {
        HSSFColor hssfcolor = (HSSFColor) color;

        if (hssfcolor.getIndex() == AUTOMATIC_COLOR) {
            return "auto";
        }
        final short[] triplet = hssfcolor.getTriplet();
        final String colorString = "#" + toHex(triplet[0]) + toHex(triplet[1]) + toHex(triplet[2]);
        return lookupStandardColorName(colorString);
    } else {
        XSSFColor xssfcolor = (XSSFColor) color;

        if (xssfcolor.isAuto()) {
            return "auto";
        }
        final byte[] triplet = xssfcolor.getRgb();
        final String colorString = "#" + toHex(triplet[0]) + toHex(triplet[1]) + toHex(triplet[2]);
        return lookupStandardColorName(colorString);

    }
}

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   ww w  .j a  v 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()) {
                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 String getBorderColorCSS(BorderSide borderSide, String attr, CellStyle cellStyle) {

    StringBuilder sb = new StringBuilder();

    XSSFColor color;
    if (cellStyle instanceof XSSFCellStyle && !((XSSFCellStyle) cellStyle).getCoreXf().getApplyBorder()) {
        // ApplyBorder is not working for Excel themes, so need to get the
        // color manually
        color = getBorderColor((XSSFCellStyle) cellStyle, borderSide);
    } else {/*from   ww w. j  a  v a2 s.c  o m*/
        color = ((XSSFCellStyle) cellStyle).getBorderColor(borderSide);
    }

    sb.append(attr);
    sb.append(":");
    if (color == null || color.isAuto()) {
        sb.append("#000;");
        return sb.toString();
    }

    byte[] argb = color.getARGB();
    if (argb == null) {
        sb.append("#000;");
        return sb.toString();
    }

    final double tint = color.getTint();
    if (tint != 0.0) {
        argb[1] = applyTint(argb[1] & 0xFF, tint);
        argb[2] = applyTint(argb[2] & 0xFF, tint);
        argb[3] = applyTint(argb[3] & 0xFF, tint);
    }

    try {
        String temp = toRGBA(argb);
        sb.append(temp);
    } catch (NumberFormatException nfe) {
        LOGGER.log(Level.FINE, nfe.getMessage() + " " + nfe.getCause(), nfe);
        sb.append(String.format("#%02x%02x%02x;", argb[1], argb[2], argb[3]));
    }

    return sb.toString();
}

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 {//www  . j av a 2s . co  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:com.vaadin.addon.spreadsheet.XSSFColorConverter.java

License:Open Source License

private String styleColor(XSSFColor color, double tint) {
    if (color == null || color.isAuto()) {
        return null;
    }//from w w w  .j  av  a2s.co m

    byte[] argb = color.getARGB();
    if (argb == null) {
        return null;
    }

    if (tint != 0.0) {
        argb[1] = applyTint(argb[1] & 0xFF, tint);
        argb[2] = applyTint(argb[2] & 0xFF, tint);
        argb[3] = applyTint(argb[3] & 0xFF, tint);
    }

    try {
        String temp = toRGBA(argb);
        return temp;
    } catch (NumberFormatException nfe) {
        LOGGER.log(Level.FINE, nfe.getMessage() + " " + nfe.getCause(), nfe);
        return String.format("#%02x%02x%02x;", argb[1], argb[2], argb[3]);
    }
}

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

License:Open Source License

private static String getXSSFColorString(XSSFColor color) {
    StringBuffer sb = new StringBuffer("[");
    if (color != null) {
        sb.append("Indexed=").append(color.getIndexed()).append(",");
        sb.append("Rgb=");
        if (color.getRGB() != null) {
            for (byte b : color.getRGB()) {
                sb.append(String.format("%02x", b).toUpperCase());
            }//from   ww  w.  j a va2s . c o m
        }
        sb.append(",");
        sb.append("Tint=").append(color.getTint()).append(",");
        sb.append("Theme=").append(color.getTheme()).append(",");
        sb.append("Auto=").append(color.isAuto());
    }
    return sb.append("]").toString();
}

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

License:Open Source License

/**
 * XSSF????//from   w  ww . ja va2 s . c  om
 * 
 * @param color XSSF
 * @return XSSF??
 */
private static String getXSSFColorString(XSSFColor color) {
    StringBuffer sb = new StringBuffer("[");
    if (color != null) {
        sb.append("Indexed=").append(color.getIndexed()).append(",");
        sb.append("Rgb=");
        if (color.getRGB() != null) {
            for (byte b : color.getRGB()) {
                sb.append(String.format("%02x", b).toUpperCase());
            }
        }
        sb.append(",");
        sb.append("Tint=").append(color.getTint()).append(",");
        sb.append("Theme=").append(color.getTheme()).append(",");
        sb.append("Auto=").append(color.isAuto());
    }
    return sb.append("]").toString();
}

From source file:org.sysmodb.xml.XSSFXMLStyleHelper.java

License:BSD License

private String getRGBString(XSSFColor colour) {
    String string = null;/* w w  w .  j a  v a2  s  .c o m*/
    // Disregard default/automatic colours, to avoid cluttering XML
    if (colour == null || colour.isAuto()) {
        return string;
    } else {
        String rgb = colour.getARGBHex();
        // XSSF has a bug where the above can sometimes return null
        // so we check here
        if (rgb != null) {
            if (rgb.length() > 6)
                rgb = rgb.substring(2, rgb.length());
            string = "#" + rgb;
        }
    }

    return string;
}