Example usage for org.apache.poi.ss.usermodel Font SS_SUPER

List of usage examples for org.apache.poi.ss.usermodel Font SS_SUPER

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Font SS_SUPER.

Prototype

short SS_SUPER

To view the source code for org.apache.poi.ss.usermodel Font SS_SUPER.

Click Source Link

Document

superscript

Usage

From source file:biz.webgate.dominoext.poi.component.kernel.WorkbookProcessor.java

License:Apache License

public synchronized void checkStyleConstantValues() {
    if (m_StyleConstantValues == null) {
        m_StyleConstantValues = new HashMap<String, Short>();
        m_StyleConstantValues.put("ALIGN_CENTER", CellStyle.ALIGN_CENTER);
        m_StyleConstantValues.put("ALIGN_CENTER_SELECTION", CellStyle.ALIGN_CENTER_SELECTION);
        m_StyleConstantValues.put("ALIGN_FILL", CellStyle.ALIGN_FILL);
        m_StyleConstantValues.put("ALIGN_GENERAL", CellStyle.ALIGN_GENERAL);
        m_StyleConstantValues.put("ALIGN_JUSTIFY", CellStyle.ALIGN_JUSTIFY);
        m_StyleConstantValues.put("ALIGN_LEFT", CellStyle.ALIGN_LEFT);
        m_StyleConstantValues.put("ALIGN_RIGHT", CellStyle.ALIGN_RIGHT);

        m_StyleConstantValues.put("BORDER_DASH_DOT", CellStyle.BORDER_DASH_DOT);
        m_StyleConstantValues.put("BORDER_DASH_DOT_DOT", CellStyle.BORDER_DASH_DOT_DOT);
        m_StyleConstantValues.put("BORDER_DASHED", CellStyle.BORDER_DASHED);
        m_StyleConstantValues.put("BORDER_DOTTED", CellStyle.BORDER_DOTTED);
        m_StyleConstantValues.put("BORDER_DOUBLE", CellStyle.BORDER_DOUBLE);
        m_StyleConstantValues.put("BORDER_HAIR", CellStyle.BORDER_HAIR);
        m_StyleConstantValues.put("BORDER_MEDIUM", CellStyle.BORDER_MEDIUM);
        m_StyleConstantValues.put("BORDER_MEDIUM_DASH_DOT", CellStyle.BORDER_MEDIUM_DASH_DOT);
        m_StyleConstantValues.put("BORDER_MEDIUM_DASH_DOT_DOT", CellStyle.BORDER_MEDIUM_DASH_DOT_DOT);
        m_StyleConstantValues.put("BORDER_MEDIUM_DASHED", CellStyle.BORDER_MEDIUM_DASHED);
        m_StyleConstantValues.put("BORDER_NONE", CellStyle.BORDER_NONE);
        m_StyleConstantValues.put("BORDER_SLANTED_DASH_DOT", CellStyle.BORDER_SLANTED_DASH_DOT);
        m_StyleConstantValues.put("BORDER_THICK", CellStyle.BORDER_THICK);
        m_StyleConstantValues.put("BORDER_THIN", CellStyle.BORDER_THIN);

        m_StyleConstantValues.put("ALT_BARS", CellStyle.ALT_BARS);
        m_StyleConstantValues.put("BIG_SPOTS", CellStyle.BIG_SPOTS);
        m_StyleConstantValues.put("BRICKS", CellStyle.BRICKS);
        m_StyleConstantValues.put("DIAMONDS", CellStyle.DIAMONDS);
        m_StyleConstantValues.put("FINE_DOTS", CellStyle.FINE_DOTS);
        m_StyleConstantValues.put("LEAST_DOTS", CellStyle.LEAST_DOTS);
        m_StyleConstantValues.put("LESS_DOTS", CellStyle.LESS_DOTS);
        m_StyleConstantValues.put("NO_FILL", CellStyle.NO_FILL);
        m_StyleConstantValues.put("SOLID_FOREGROUND", CellStyle.SOLID_FOREGROUND);
        m_StyleConstantValues.put("SPARSE_DOTS", CellStyle.SPARSE_DOTS);
        m_StyleConstantValues.put("SQUARES", CellStyle.SQUARES);
        m_StyleConstantValues.put("THICK_BACKWARD_DIAG", CellStyle.THICK_BACKWARD_DIAG);
        m_StyleConstantValues.put("THICK_FORWARD_DIAG", CellStyle.THICK_FORWARD_DIAG);
        m_StyleConstantValues.put("THICK_HORZ_BANDS", CellStyle.THICK_HORZ_BANDS);
        m_StyleConstantValues.put("THICK_VERT_BANDS", CellStyle.THICK_VERT_BANDS);
        m_StyleConstantValues.put("THIN_BACKWARD_DIAG", CellStyle.THIN_BACKWARD_DIAG);
        m_StyleConstantValues.put("THIN_FORWARD_DIAG", CellStyle.THIN_FORWARD_DIAG);
        m_StyleConstantValues.put("THIN_HORZ_BANDS", CellStyle.THIN_HORZ_BANDS);
        m_StyleConstantValues.put("THIN_VERT_BANDS", CellStyle.THIN_VERT_BANDS);

        m_StyleConstantValues.put("VERTICAL_BOTTOM", CellStyle.VERTICAL_BOTTOM);
        m_StyleConstantValues.put("VERTICAL_CENTER", CellStyle.VERTICAL_CENTER);
        m_StyleConstantValues.put("VERTICAL_JUSTIFY", CellStyle.VERTICAL_JUSTIFY);
        m_StyleConstantValues.put("VERTICAL_TOP", CellStyle.VERTICAL_TOP);

        m_StyleConstantValues.put("SS_NONE", Font.SS_NONE);
        m_StyleConstantValues.put("SS_SUPER", Font.SS_SUPER);
        m_StyleConstantValues.put("SS_SUB", Font.SS_SUB);

        m_StyleConstantValues.put("BOLDWEIGHT_BOLD", Font.BOLDWEIGHT_BOLD);
        m_StyleConstantValues.put("BOLDWEIGHT_NORMAL", Font.BOLDWEIGHT_NORMAL);

    }//www. java2s  . c o  m

    if (m_StyleByteConstantValues == null) {
        m_StyleByteConstantValues = new HashMap<String, Byte>();
        m_StyleByteConstantValues.put("U_NONE", Font.U_NONE);
        m_StyleByteConstantValues.put("U_SINGLE", Font.U_SINGLE);
        m_StyleByteConstantValues.put("U_DOUBLE", Font.U_DOUBLE);
        m_StyleByteConstantValues.put("U_SINGLE_ACCOUNTING", Font.U_SINGLE_ACCOUNTING);
        m_StyleByteConstantValues.put("U_DOUBLE_ACCOUNTING", Font.U_DOUBLE_ACCOUNTING);
    }
}

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

License:Open Source License

private static String getFontStyle(final Font font) {
    final StringBuffer sb = new StringBuffer();
    if (font.getBoldweight() == Font.BOLDWEIGHT_BOLD) {
        sb.append("bold ");
    }//from  w  w  w .  j  a va2  s .  c  o  m
    if (font.getItalic()) {
        sb.append("italic ");
    }
    if (font.getStrikeout()) {
        sb.append("strikethrough ");
    }
    if (font.getTypeOffset() == Font.SS_SUB) {
        sb.append("subscript ");
    } else if (font.getTypeOffset() == Font.SS_SUPER) {
        sb.append("superscript ");
    }
    switch (font.getUnderline()) {
    case Font.U_NONE:
        break;
    case Font.U_SINGLE:
        sb.append("underline ");
        break;
    case Font.U_SINGLE_ACCOUNTING:
        sb.append("underline-accounting ");
        break;
    case Font.U_DOUBLE:
        sb.append("underline-double ");
        break;
    case Font.U_DOUBLE_ACCOUNTING:
        sb.append("underline-double-accounting ");
        break;
    default:
        sb.append("underline-unknown ");
        break;
    }
    if (sb.length() == 0) {
        return "normal";
    }
    return sb.substring(0, sb.length() - 1);
}

From source file:jdbreport.model.io.xls.poi.Excel2003Writer.java

License:Apache License

private Font getFont(short fontIndex, AttributeSet attributeSet, Workbook wb) {
    Font font = null;//ww w.j a  va  2s.co  m
    String family = null;
    String sizeStr = null;
    short color = 0;
    boolean bold = false;
    boolean italic = false;
    boolean underline = false;
    boolean line_through = false;
    boolean sub = false;
    boolean sup = false;
    Enumeration<?> en = attributeSet.getAttributeNames();
    while (en.hasMoreElements()) {
        Object key = en.nextElement();
        String name = key.toString();
        String attribute = attributeSet.getAttribute(key).toString();

        switch (name) {
        case "font-weight":
            bold = attribute.equals("bold");
            break;
        case "font-style":
            italic = attribute.equals("italic");
            break;
        case "text-decoration":
            if (attribute.equals("underline")) {
                underline = true;
            } else if (attribute.equals("line-through")) {
                line_through = true;
            }
            break;
        case "font-family":
            family = attribute;
            break;
        case "font-size":
            sizeStr = attribute;

            break;
        case "color":
            Color fontColor = Utils.colorByName(attribute);
            if (fontColor == null) {
                try {
                    fontColor = Utils.stringToColor(attribute);
                } catch (Exception ignored) {

                }
            }
            if (fontColor != null) {
                color = colorToIndex(wb, fontColor);
            }
            break;
        case "vertical-align":
            if (attribute.equals("sub")) {
                sub = true;
            } else if (attribute.equals("sup")) {
                sup = true;
            }
            break;
        }
    }
    if (family != null || bold || italic || underline || line_through || color > 0 || sizeStr != null || sub
            || sup) {

        font = wb.createFont();
        if (fontIndex > 0) {
            Font parentFont = wb.getFontAt(fontIndex);
            if (parentFont != null) {
                font.setBold(parentFont.getBold());
                font.setColor(parentFont.getColor());
                try {
                    font.setCharSet(parentFont.getCharSet());
                } catch (Throwable ignored) {
                }
                font.setFontHeight(parentFont.getFontHeight());
                font.setFontName(parentFont.getFontName());
                font.setItalic(parentFont.getItalic());
                font.setStrikeout(parentFont.getStrikeout());
                font.setUnderline(parentFont.getUnderline());
                font.setTypeOffset(parentFont.getTypeOffset());
            }
        }
        if (family != null) {
            font.setFontName(family);
        }
        if (bold) {
            font.setBold(true);
        }
        if (italic) {
            font.setItalic(italic);
        }
        if (underline) {
            font.setUnderline(Font.U_SINGLE);
        }
        if (line_through) {
            font.setStrikeout(line_through);
        }
        if (color > 0) {
            font.setColor(color);
        }
        if (sizeStr != null) {
            short size = (short) Float.parseFloat(sizeStr);
            if (sizeStr.charAt(0) == '+' || sizeStr.charAt(0) == '-') {
                size = (short) (Content.pointToSize(font.getFontHeightInPoints()) + size);
            }
            font.setFontHeightInPoints(Content.sizeToPoints(size));
        }
        if (sup) {
            font.setTypeOffset(Font.SS_SUPER);
        } else if (sub) {
            font.setTypeOffset(Font.SS_SUB);
        }
    }
    return font;
}

From source file:org.joeffice.spreadsheet.TableStyleable.java

License:Apache License

/**
 * Add the attribute as defined in {@link AttributedString} to the {@link MutableAttributeSet} for the JTextPane.
 *
 * @see java.awt.font.TextAttribute/*from   w ww. j  av  a 2s  .c  om*/
 */
protected void addAttribute(AttributedCharacterIterator.Attribute attribute, Object attributeValue, Cell cell) {
    CellStyle oldStyle = cell.getCellStyle();
    Workbook workbook = cell.getSheet().getWorkbook();
    CellStyle style = cell.getSheet().getWorkbook().createCellStyle();
    style.cloneStyleFrom(oldStyle);
    Font newFont = copyFont(cell);
    if (attribute == FAMILY) {
        newFont.setFontName((String) attributeValue);
        CellUtil.setFont(cell, workbook, newFont);
    } else if (attribute == FOREGROUND) {
        Color color = (Color) attributeValue;
        if (cell instanceof XSSFCell) {
            ((XSSFCellStyle) style).setFillForegroundColor(new XSSFColor(color));
        } else {
            HSSFWorkbook xlsWorkbook = (HSSFWorkbook) workbook;
            HSSFColor xlsColor = xlsWorkbook.getCustomPalette().findColor((byte) color.getRed(),
                    (byte) color.getGreen(), (byte) color.getBlue());
            if (xlsColor == null) {
                xlsColor = xlsWorkbook.getCustomPalette().addColor((byte) color.getRed(),
                        (byte) color.getGreen(), (byte) color.getBlue());
            }
            style.setFillForegroundColor(xlsColor.getIndex());
        }
        style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    } else if (attribute == BACKGROUND) {
        Color color = (Color) attributeValue;
        if (cell instanceof XSSFCell) {
            ((XSSFCellStyle) style).setFillBackgroundColor(new XSSFColor(color));
        } else {
            HSSFWorkbook xlsWorkbook = (HSSFWorkbook) workbook;
            HSSFColor xlsColor = xlsWorkbook.getCustomPalette().findColor((byte) color.getRed(),
                    (byte) color.getGreen(), (byte) color.getBlue());
            if (xlsColor == null) {
                xlsColor = xlsWorkbook.getCustomPalette().addColor((byte) color.getRed(),
                        (byte) color.getGreen(), (byte) color.getBlue());
            }
            style.setFillBackgroundColor(xlsColor.getIndex());
        }
    } else if (attribute == WEIGHT) {
        short boldValue = Font.BOLDWEIGHT_BOLD;
        if (newFont.getBoldweight() == Font.BOLDWEIGHT_BOLD) {
            boldValue = Font.BOLDWEIGHT_NORMAL;
        }
        newFont.setBoldweight(boldValue);
        CellUtil.setFont(cell, workbook, newFont);
    } else if (attribute == UNDERLINE) {
        byte underlineValue = Font.U_SINGLE;
        if (newFont.getUnderline() == Font.U_SINGLE) {
            underlineValue = Font.U_NONE;
        }
        newFont.setUnderline(underlineValue);
        CellUtil.setFont(cell, workbook, newFont);
    } else if (attribute == SUPERSCRIPT) {
        short superscriptValue = Font.SS_NONE;
        if (SUPERSCRIPT_SUB.equals(attributeValue)) {
            superscriptValue = Font.SS_SUB;
        } else if (SUPERSCRIPT_SUPER.equals(attributeValue)) {
            superscriptValue = Font.SS_SUPER;
        }
        newFont.setTypeOffset(superscriptValue);
        CellUtil.setFont(cell, workbook, newFont);
    } else if (attribute == STRIKETHROUGH) {
        boolean strikeThrough = true;
        if (newFont.getStrikeout()) {
            strikeThrough = false;
        }
        newFont.setStrikeout(strikeThrough);
        CellUtil.setFont(cell, workbook, newFont);
    } else if (attribute == POSTURE) {
        boolean italic = true;
        if (newFont.getItalic()) {
            italic = false;
        }
        newFont.setItalic(italic);
        CellUtil.setFont(cell, workbook, newFont);
    } else if (attribute == SIZE) {
        newFont.setFontHeightInPoints(((Number) attributeValue).shortValue());
        CellUtil.setFont(cell, workbook, newFont);
    } else if (attribute == JUSTIFICATION) {
        CellUtil.setAlignment(cell, workbook, CellStyle.ALIGN_JUSTIFY);
    } else if (attribute == ALIGNMENT) {
        if (attributeValue.equals(StyleConstants.ALIGN_LEFT)) {
            CellUtil.setAlignment(cell, workbook, CellStyle.ALIGN_LEFT);
        } else if (attributeValue.equals(StyleConstants.ALIGN_RIGHT)) {
            CellUtil.setAlignment(cell, workbook, CellStyle.ALIGN_RIGHT);
        } else if (attributeValue.equals(StyleConstants.ALIGN_CENTER)) {
            CellUtil.setAlignment(cell, workbook, CellStyle.ALIGN_CENTER);
        }
    } else if (attribute == INDENTATION) {
        style.setIndention(((Number) attributeValue).shortValue());
    } else if (attribute == TEXT_TRANSFORM) {
        String text = CellUtils.getFormattedText(cell);
        String transformedText = ((TextTransformer) attributeValue).transformText(text);
        cell.setCellValue(transformedText);
    }
}