Example usage for org.apache.poi.hssf.converter AbstractExcelUtils getColor

List of usage examples for org.apache.poi.hssf.converter AbstractExcelUtils getColor

Introduction

In this page you can find the example usage for org.apache.poi.hssf.converter AbstractExcelUtils getColor.

Prototype

public static String getColor(HSSFColor color) 

Source Link

Usage

From source file:com.wangzhu.poi.ExcelToHtmlConverter.java

License:Apache License

protected String buildStyle(HSSFWorkbook workbook, HSSFCellStyle cellStyle) {
    StringBuffer style = new StringBuffer();

    style.append("white-space:pre-wrap;");
    ExcelToHtmlUtils.appendAlign(style, cellStyle.getAlignment());

    if (cellStyle.getFillPattern() == 0) {
        // no fill
    } else if (cellStyle.getFillPattern() == 1) {
        final HSSFColor foregroundColor = cellStyle.getFillForegroundColorColor();
        if (foregroundColor != null) {
            style.append("background-color:" + AbstractExcelUtils.getColor(foregroundColor) + ";");
        }//from w ww. ja v  a 2 s  .c  o  m
    } else {
        final HSSFColor backgroundColor = cellStyle.getFillBackgroundColorColor();
        if (backgroundColor != null) {
            style.append("background-color:" + AbstractExcelUtils.getColor(backgroundColor) + ";");
        }
    }

    this.buildStyle_border(workbook, style, "top", cellStyle.getBorderTop(), cellStyle.getTopBorderColor());
    this.buildStyle_border(workbook, style, "right", cellStyle.getBorderRight(),
            cellStyle.getRightBorderColor());
    this.buildStyle_border(workbook, style, "bottom", cellStyle.getBorderBottom(),
            cellStyle.getBottomBorderColor());
    this.buildStyle_border(workbook, style, "left", cellStyle.getBorderLeft(), cellStyle.getLeftBorderColor());

    HSSFFont font = cellStyle.getFont(workbook);
    this.buildStyle_font(workbook, style, font);

    return style.toString();
}

From source file:com.wangzhu.poi.ExcelToHtmlConverter.java

License:Apache License

private void buildStyle_border(HSSFWorkbook workbook, StringBuffer style, String type, short xlsBorder,
        short borderColor) {
    if (xlsBorder == CellStyle.BORDER_NONE) {
        return;/*from  ww w.  ja  va2  s  .  c  om*/
    }

    StringBuffer borderStyle = new StringBuffer();
    borderStyle.append(AbstractExcelUtils.getBorderWidth(xlsBorder));
    borderStyle.append(' ');
    borderStyle.append(AbstractExcelUtils.getBorderStyle(xlsBorder));

    final HSSFColor color = workbook.getCustomPalette().getColor(borderColor);
    if (color != null) {
        borderStyle.append(' ');
        borderStyle.append(AbstractExcelUtils.getColor(color));
    }

    style.append("border-" + type + ":" + borderStyle + ";");
}

From source file:com.wangzhu.poi.ExcelToHtmlConverter.java

License:Apache License

void buildStyle_font(HSSFWorkbook workbook, StringBuffer style, HSSFFont font) {
    switch (font.getBoldweight()) {
    case Font.BOLDWEIGHT_BOLD:
        style.append("font-weight:bold;");
        break;//  www  . j  ava 2  s  .  c om
    case Font.BOLDWEIGHT_NORMAL:
        // by default, not not increase HTML size
        // style.append( "font-weight: normal; " );
        break;
    }

    final HSSFColor fontColor = workbook.getCustomPalette().getColor(font.getColor());
    if (fontColor != null) {
        style.append("color: " + AbstractExcelUtils.getColor(fontColor) + "; ");
    }

    if (font.getFontHeightInPoints() != 0) {
        style.append("font-size:" + font.getFontHeightInPoints() + "pt;");
    }

    if (font.getItalic()) {
        style.append("font-style:italic;");
    }
}