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

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

Introduction

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

Prototype

@Override
public byte[] getRGB() 

Source Link

Document

Standard Red Green Blue ctColor value (RGB).

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 ww . j  a  va 2 s .  c om*/

    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;/*from   w w w  .j ava  2 s .  com*/
    }

    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";
    }//ww  w  . j  a 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:de.escnet.ExcelTable.java

License:Open Source License

private String getHtmlColor(XSSFColor color) {
    StringBuilder builder = new StringBuilder("#");

    byte[] rgb = color.getRgb();
    for (byte c : rgb) {
        int i = (int) c;
        if (i < 0) {
            i += 256;//from   ww  w. j a v  a 2s  . com
        }

        String cs = Integer.toHexString(i);
        if (cs.length() == 1) {
            builder.append('0');
        }

        builder.append(cs);
    }

    return builder.toString();
}

From source file:mil.tatrc.physiology.utilities.testing.validation.ValidationMatrix.java

License:Apache License

public static void convert(String from, String to) throws IOException {
    FileInputStream xlFile = new FileInputStream(new File(from));
    // Read workbook into HSSFWorkbook
    XSSFWorkbook xlWBook = new XSSFWorkbook(xlFile);
    List<SheetSummary> sheetSummaries = new ArrayList<SheetSummary>();// has to be an ordered list as sheet names can only be so long
    Map<String, String> refs = new HashMap<String, String>();

    List<Sheet> Sheets = new ArrayList<Sheet>();

    for (int s = 0; s < xlWBook.getNumberOfSheets(); s++) {
        XSSFSheet xlSheet = xlWBook.getSheetAt(s);
        Log.info("Processing Sheet : " + xlSheet.getSheetName());
        if (xlSheet.getSheetName().equals("Summary")) {
            int rows = xlSheet.getPhysicalNumberOfRows();
            for (int r = 1; r < rows; r++) {
                XSSFRow row = xlSheet.getRow(r);
                if (row == null)
                    continue;
                SheetSummary ss = new SheetSummary();
                sheetSummaries.add(ss);/*  w ww . j  a va  2s  . c  o  m*/
                ss.name = row.getCell(0).getStringCellValue();
                ss.description = row.getCell(1).getStringCellValue();
                ss.validationType = row.getCell(2).getStringCellValue();
            }
        } else if (xlSheet.getSheetName().equals("References")) {
            int rows = xlSheet.getPhysicalNumberOfRows();
            for (int r = 1; r < rows; r++) {
                XSSFRow row = xlSheet.getRow(r);
                if (row == null)
                    continue;
                refs.put("\\[" + r + "\\]", "@cite " + row.getCell(1).getStringCellValue());
            }
        } else {
            int rows = xlSheet.getPhysicalNumberOfRows();
            Sheet sheet = new Sheet();
            sheet.summary = sheetSummaries.get(s - 2);
            Sheets.add(sheet);

            int cells = xlSheet.getRow(0).getPhysicalNumberOfCells();

            for (int r = 0; r < rows; r++) {
                XSSFRow row = xlSheet.getRow(r);
                if (row == null)
                    continue;

                String cellValue = null;

                for (int c = 0; c < cells; c++) {
                    List<Cell> column;
                    if (r == 0) {
                        column = new ArrayList<Cell>();
                        sheet.table.add(column);
                    } else {
                        column = sheet.table.get(c);
                    }

                    XSSFCell cell = row.getCell(c);
                    if (cell == null) {
                        column.add(new Cell("", Agreement.NA, refs));
                        continue;
                    }
                    cellValue = null;
                    switch (cell.getCellType()) {
                    case XSSFCell.CELL_TYPE_NUMERIC:
                        cellValue = Double.toString(cell.getNumericCellValue());
                        break;
                    case XSSFCell.CELL_TYPE_STRING:
                        cellValue = cell.getStringCellValue();
                        break;
                    }
                    if (cellValue == null || cellValue.isEmpty())
                        column.add(new Cell("", Agreement.NA, refs));
                    else {
                        Agreement a = Agreement.NA;
                        XSSFColor color = cell.getCellStyle().getFillForegroundColorColor();
                        if (color != null) {
                            byte[] rgb = color.getRGB();
                            if (rgb[0] < -25 && rgb[1] > -25 && rgb[2] < -25) {
                                a = Agreement.Good;
                                sheet.summary.goodAgreement++;
                            } else if (rgb[0] > -25 && rgb[1] > -25 && rgb[2] < -25) {
                                a = Agreement.Ok;
                                sheet.summary.okAgreement++;
                            } else if (rgb[0] > -25 && rgb[1] < -25 && rgb[2] < -25) {
                                a = Agreement.Bad;
                                sheet.summary.badAgreement++;
                            }
                        }
                        column.add(new Cell(cellValue, a, refs));
                    }
                }
            }
        }
    }
    xlWBook.close();
    xlFile.close(); //close xls

    // Generate our Tables for each Sheet
    PrintWriter writer = null;
    try {
        String name = from.substring(from.lastIndexOf('/') + 1, from.lastIndexOf('.')) + "Scenarios";

        writer = new PrintWriter(to + name + "Summary.md", "UTF-8");
        writer.println(
                "|Scenario|Description|Validation Type|Good agreement|General agreement with deviations|Some major disagreements|");
        writer.println("|--- |--- |:---: |:---: |:---: |:---: |");
        for (Sheet sheet : Sheets) {
            writer.println("|" + sheet.summary.name + "|" + sheet.summary.description + "|"
                    + sheet.summary.validationType + "|" + success + sheet.summary.goodAgreement + endSpan + "|"
                    + warning + sheet.summary.okAgreement + endSpan + "|" + danger + sheet.summary.badAgreement
                    + endSpan + "|");
        }
        writer.close();

        // Create file and start the table
        writer = new PrintWriter(to + name + ".md", "UTF-8");
        writer.println(name + " {#" + name + "}");
        writer.println("=======");
        writer.println();

        writer.println();

        for (Sheet sheet : Sheets) {
            Log.info("Writing table : " + sheet.summary.name);
            writer.println("## " + sheet.summary.name);

            writer.println(sheet.summary.description);
            writer.println("We used a " + sheet.summary.validationType + " validation method(s).");
            writer.println("");

            for (int row = 0; row < sheet.table.get(0).size(); row++) {
                for (int col = 0; col < sheet.table.size(); col++) {
                    writer.print("|" + sheet.table.get(col).get(row).text);
                }
                writer.println("|");
                if (row == 0) {
                    for (int col = 0; col < sheet.table.size(); col++) {
                        writer.print("|---   ");
                    }
                    writer.println("|");
                }
            }
            writer.println();
            writer.println();
        }
        writer.close();
    } catch (Exception ex) {
        Log.error("Error writing tables for " + from, ex);
        writer.close();
    }
}

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   w  w w . j  a  va  2  s  .c  om*/
        }
        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  .j a v  a2s .c o  m*/
 * 
 * @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.tiefaces.components.websheet.utility.ColorUtility.java

License:MIT License

/**
 * Convert xssfcolor to triple let numbers.
 * /* w  ww.j  ava  2  s .c  o  m*/
 * @param xssfColor
 *            xssf color.
 * @return triple lets.
 */
public static short[] getTripletFromXSSFColor(final XSSFColor xssfColor) {

    short[] rgbfix = { RGB8BITS, RGB8BITS, RGB8BITS };
    if (xssfColor != null) {
        byte[] rgb = xssfColor.getRGBWithTint();
        if (rgb == null) {
            rgb = xssfColor.getRGB();
        }
        // Bytes are signed, so values of 128+ are negative!
        // 0: red, 1: green, 2: blue
        rgbfix[0] = (short) ((rgb[0] < 0) ? (rgb[0] + RGB8BITS) : rgb[0]);
        rgbfix[1] = (short) ((rgb[1] < 0) ? (rgb[1] + RGB8BITS) : rgb[1]);
        rgbfix[2] = (short) ((rgb[2] < 0) ? (rgb[2] + RGB8BITS) : rgb[2]);
    }
    return rgbfix;
}

From source file:ru.spb.nicetu.tableviewer.server.XSSFHtmlHelper.java

License:Apache License

private void styleColor(Formatter out, String attr, XSSFColor color, boolean isBuiltIn) {
    if (color == null || color.isAuto())
        return;//from   w  w w .  j  a  va2 s  .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
    if (!isBuiltIn)
        out.format("  ");
    out.format("%s: #%02x%02x%02x;", attr, rgb[0], rgb[1], rgb[2]);
    if (!isBuiltIn)
        out.format("%n");
    byte[] argb = color.getARgb();
    if (argb == null) {
        return;
    }
    if (!isBuiltIn)
        out.format("  ");
    out.format("%s: rgba(0x%02x, 0x%02x, 0x%02x, 0x%02x);", attr, argb[3], argb[0], argb[1], argb[2]);
    if (!isBuiltIn)
        out.format("%n");
}