Search in sources :

Example 11 with HSSFColor

use of org.apache.poi.hssf.util.HSSFColor in project poi by apache.

the class ExcelToFoConverter method processCellStyleBorder.

protected void processCellStyleBorder(HSSFWorkbook workbook, Element cellTarget, String type, BorderStyle xlsBorder, short borderColor) {
    if (xlsBorder == BorderStyle.NONE)
        return;
    StringBuilder borderStyle = new StringBuilder();
    borderStyle.append(ExcelToHtmlUtils.getBorderWidth(xlsBorder));
    final HSSFColor color = workbook.getCustomPalette().getColor(borderColor);
    if (color != null) {
        borderStyle.append(' ');
        borderStyle.append(ExcelToHtmlUtils.getColor(color));
        borderStyle.append(' ');
        borderStyle.append(ExcelToHtmlUtils.getBorderStyle(xlsBorder));
    }
    cellTarget.setAttribute("border-" + type, borderStyle.toString());
}
Also used : HSSFColor(org.apache.poi.hssf.util.HSSFColor)

Example 12 with HSSFColor

use of org.apache.poi.hssf.util.HSSFColor in project poi by apache.

the class ExcelToHtmlConverter method buildStyle.

protected String buildStyle(HSSFWorkbook workbook, HSSFCellStyle cellStyle) {
    StringBuilder style = new StringBuilder();
    style.append("white-space:pre-wrap;");
    ExcelToHtmlUtils.appendAlign(style, cellStyle.getAlignment());
    switch(cellStyle.getFillPattern()) {
        // no fill
        case 0:
            break;
        case 1:
            final HSSFColor foregroundColor = cellStyle.getFillForegroundColorColor();
            if (foregroundColor == null)
                break;
            String fgCol = ExcelToHtmlUtils.getColor(foregroundColor);
            style.append("background-color:" + fgCol + ";");
            break;
        default:
            final HSSFColor backgroundColor = cellStyle.getFillBackgroundColorColor();
            if (backgroundColor == null)
                break;
            String bgCol = ExcelToHtmlUtils.getColor(backgroundColor);
            style.append("background-color:" + bgCol + ";");
            break;
    }
    buildStyle_border(workbook, style, "top", cellStyle.getBorderTopEnum(), cellStyle.getTopBorderColor());
    buildStyle_border(workbook, style, "right", cellStyle.getBorderRightEnum(), cellStyle.getRightBorderColor());
    buildStyle_border(workbook, style, "bottom", cellStyle.getBorderBottomEnum(), cellStyle.getBottomBorderColor());
    buildStyle_border(workbook, style, "left", cellStyle.getBorderLeftEnum(), cellStyle.getLeftBorderColor());
    HSSFFont font = cellStyle.getFont(workbook);
    buildStyle_font(workbook, style, font);
    return style.toString();
}
Also used : HSSFColor(org.apache.poi.hssf.util.HSSFColor) HSSFFont(org.apache.poi.hssf.usermodel.HSSFFont) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString)

Example 13 with HSSFColor

use of org.apache.poi.hssf.util.HSSFColor in project poi by apache.

the class ExcelToFoConverter method processCellStyleFont.

protected void processCellStyleFont(HSSFWorkbook workbook, Element blockTarget, HSSFFont font) {
    Triplet triplet = new Triplet();
    triplet.fontName = font.getFontName();
    switch(font.getBoldweight()) {
        case HSSFFont.BOLDWEIGHT_BOLD:
            triplet.bold = true;
            break;
        case HSSFFont.BOLDWEIGHT_NORMAL:
        default:
            triplet.bold = false;
            break;
    }
    if (font.getItalic()) {
        triplet.italic = true;
    }
    getFontReplacer().update(triplet);
    setBlockProperties(blockTarget, triplet);
    final HSSFColor fontColor = workbook.getCustomPalette().getColor(font.getColor());
    if (fontColor != null)
        blockTarget.setAttribute("color", ExcelToHtmlUtils.getColor(fontColor));
    if (font.getFontHeightInPoints() != 0)
        blockTarget.setAttribute("font-size", font.getFontHeightInPoints() + "pt");
}
Also used : Triplet(org.apache.poi.hwpf.converter.FontReplacer.Triplet) HSSFColor(org.apache.poi.hssf.util.HSSFColor)

Example 14 with HSSFColor

use of org.apache.poi.hssf.util.HSSFColor in project poi by apache.

the class HSSFPalette method findSimilarColor.

/**
     * Finds the closest matching color in the custom palette.  The
     * method for finding the distance between the colors is fairly
     * primative.
     *
     * @param red   The red component of the color to match.
     * @param green The green component of the color to match.
     * @param blue  The blue component of the color to match.
     * @return  The closest color or null if there are no custom
     *          colors currently defined.
     */
public HSSFColor findSimilarColor(int red, int green, int blue) {
    HSSFColor result = null;
    int minColorDistance = Integer.MAX_VALUE;
    byte[] b = _palette.getColor(PaletteRecord.FIRST_COLOR_INDEX);
    for (short i = PaletteRecord.FIRST_COLOR_INDEX; b != null; b = _palette.getColor(++i)) {
        int colorDistance = Math.abs(red - unsignedInt(b[0])) + Math.abs(green - unsignedInt(b[1])) + Math.abs(blue - unsignedInt(b[2]));
        if (colorDistance < minColorDistance) {
            minColorDistance = colorDistance;
            result = getColor(i);
        }
    }
    return result;
}
Also used : HSSFColor(org.apache.poi.hssf.util.HSSFColor)

Example 15 with HSSFColor

use of org.apache.poi.hssf.util.HSSFColor in project poi by apache.

the class TestHSSFPalette method compareToDefaults.

private void compareToDefaults(ColorComparator c) {
    Map<Integer, HSSFColor> colors = HSSFColor.getIndexHash();
    Iterator<Integer> it = colors.keySet().iterator();
    while (it.hasNext()) {
        Number index = it.next();
        HSSFColor expectedColor = colors.get(index);
        HSSFColor paletteColor = _hssfPalette.getColor(index.shortValue());
        c.compare(expectedColor, paletteColor);
    }
}
Also used : HSSFColor(org.apache.poi.hssf.util.HSSFColor)

Aggregations

HSSFColor (org.apache.poi.hssf.util.HSSFColor)18 Test (org.junit.Test)4 Color (java.awt.Color)2 HSSFFont (org.apache.poi.hssf.usermodel.HSSFFont)2 HSSFRichTextString (org.apache.poi.hssf.usermodel.HSSFRichTextString)2 Cell (org.apache.poi.ss.usermodel.Cell)2 Row (org.apache.poi.ss.usermodel.Row)2 Sheet (org.apache.poi.ss.usermodel.Sheet)2 ExcelColDVO (com.kyj.fx.voeditor.visual.excels.base.ExcelColDVO)1 ExcelDataDVO (com.kyj.fx.voeditor.visual.excels.base.ExcelDataDVO)1 ExcelSVO (com.kyj.fx.voeditor.visual.excels.base.ExcelSVO)1 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Triplet (org.apache.poi.hwpf.converter.FontReplacer.Triplet)1 CellDateFormatter (org.apache.poi.ss.format.CellDateFormatter)1 CellStyle (org.apache.poi.ss.usermodel.CellStyle)1 Color (org.apache.poi.ss.usermodel.Color)1 FormulaEvaluator (org.apache.poi.ss.usermodel.FormulaEvaluator)1 Workbook (org.apache.poi.ss.usermodel.Workbook)1