Example usage for org.apache.poi.hssf.usermodel HSSFFont getFontName

List of usage examples for org.apache.poi.hssf.usermodel HSSFFont getFontName

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFFont getFontName.

Prototype


public String getFontName() 

Source Link

Document

get the name for the font (i.e.

Usage

From source file:net.sf.jasperreports.engine.export.JRXlsExporter.java

License:Open Source License

/**
 *
 *///from  w  w  w  .  j a va 2  s.c o m
protected HSSFFont getLoadedFont(JRFont font, short forecolor, Map<Attribute, Object> attributes,
        Locale locale) {
    HSSFFont cellFont = null;

    String fontName = font.getFontName();

    FontInfo fontInfo = FontUtil.getInstance(jasperReportsContext).getFontInfo(fontName, locale);
    if (fontInfo != null) {
        //fontName found in font extensions
        FontFamily family = fontInfo.getFontFamily();
        String exportFont = family.getExportFont(getExporterKey());
        if (exportFont != null) {
            fontName = exportFont;
        }
    }

    short superscriptType = HSSFFont.SS_NONE;

    if (attributes != null && attributes.get(TextAttribute.SUPERSCRIPT) != null) {
        Object value = attributes.get(TextAttribute.SUPERSCRIPT);
        if (TextAttribute.SUPERSCRIPT_SUPER.equals(value)) {
            superscriptType = HSSFFont.SS_SUPER;
        } else if (TextAttribute.SUPERSCRIPT_SUB.equals(value)) {
            superscriptType = HSSFFont.SS_SUB;
        }

    }
    boolean isFontSizeFixEnabled = getCurrentItemConfiguration().isFontSizeFixEnabled();
    for (int i = 0; i < loadedFonts.size(); i++) {
        HSSFFont cf = (HSSFFont) loadedFonts.get(i);

        short fontSize = (short) font.getFontsize();
        if (isFontSizeFixEnabled) {
            fontSize -= 1;
        }
        if (cf.getFontName().equals(fontName) && (cf.getColor() == forecolor)
                && (cf.getFontHeightInPoints() == fontSize)
                && ((cf.getUnderline() == HSSFFont.U_SINGLE) ? (font.isUnderline()) : (!font.isUnderline()))
                && (cf.getStrikeout() == font.isStrikeThrough())
                && ((cf.getBoldweight() == HSSFFont.BOLDWEIGHT_BOLD) ? (font.isBold()) : (!font.isBold()))
                && (cf.getItalic() == font.isItalic()) && (cf.getTypeOffset() == superscriptType)) {
            cellFont = cf;
            break;
        }
    }

    if (cellFont == null) {
        cellFont = workbook.createFont();

        cellFont.setFontName(fontName);
        cellFont.setColor(forecolor);

        short fontSize = (short) font.getFontsize();
        if (isFontSizeFixEnabled) {
            fontSize -= 1;
        }
        cellFont.setFontHeightInPoints(fontSize);

        if (font.isUnderline()) {
            cellFont.setUnderline(HSSFFont.U_SINGLE);
        }
        if (font.isStrikeThrough()) {
            cellFont.setStrikeout(true);
        }
        if (font.isBold()) {
            cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        }
        if (font.isItalic()) {
            cellFont.setItalic(true);
        }

        cellFont.setTypeOffset(superscriptType);
        loadedFonts.add(cellFont);
    }

    return cellFont;
}

From source file:net.sf.jasperreports.engine.export.JRXlsMetadataExporter.java

License:Open Source License

/**
 *
 *///  ww  w  . jav  a2  s.  co m
protected HSSFFont getLoadedFont(JRFont font, short forecolor, Map<Attribute, Object> attributes,
        Locale locale) {

    HSSFFont cellFont = null;
    String fontName = font.getFontName();
    FontInfo fontInfo = FontUtil.getInstance(jasperReportsContext).getFontInfo(fontName, locale);
    if (fontInfo != null) {
        //fontName found in font extensions
        FontFamily family = fontInfo.getFontFamily();
        String exportFont = family.getExportFont(getExporterKey());
        if (exportFont != null) {
            fontName = exportFont;
        }
    }

    boolean isFontSizeFixEnabled = getCurrentItemConfiguration().isFontSizeFixEnabled();

    short superscriptType = HSSFFont.SS_NONE;

    if (attributes != null && attributes.get(TextAttribute.SUPERSCRIPT) != null) {
        Object value = attributes.get(TextAttribute.SUPERSCRIPT);
        if (TextAttribute.SUPERSCRIPT_SUPER.equals(value)) {
            superscriptType = HSSFFont.SS_SUPER;
        } else if (TextAttribute.SUPERSCRIPT_SUB.equals(value)) {
            superscriptType = HSSFFont.SS_SUB;
        }
    }
    for (int i = 0; i < loadedFonts.size(); i++) {
        HSSFFont cf = (HSSFFont) loadedFonts.get(i);
        short fontSize = (short) font.getFontsize();
        if (isFontSizeFixEnabled) {
            fontSize -= 1;
        }
        if (cf.getFontName().equals(fontName) && (cf.getColor() == forecolor)
                && (cf.getFontHeightInPoints() == fontSize)
                && ((cf.getUnderline() == HSSFFont.U_SINGLE) ? (font.isUnderline()) : (!font.isUnderline()))
                && (cf.getStrikeout() == font.isStrikeThrough())
                && ((cf.getBoldweight() == HSSFFont.BOLDWEIGHT_BOLD) ? (font.isBold()) : (!font.isBold()))
                && (cf.getItalic() == font.isItalic()) && (cf.getTypeOffset() == superscriptType)) {
            cellFont = cf;
            break;
        }
    }

    if (cellFont == null) {

        cellFont = workbook.createFont();
        cellFont.setFontName(fontName);
        cellFont.setColor(forecolor);
        short fontSize = (short) font.getFontsize();
        if (isFontSizeFixEnabled) {
            fontSize -= 1;
        }
        cellFont.setFontHeightInPoints(fontSize);

        if (font.isUnderline()) {
            cellFont.setUnderline(HSSFFont.U_SINGLE);
        }
        if (font.isStrikeThrough()) {
            cellFont.setStrikeout(true);
        }
        if (font.isBold()) {
            cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        }
        if (font.isItalic()) {
            cellFont.setItalic(true);
        }

        cellFont.setTypeOffset(superscriptType);
        loadedFonts.add(cellFont);
    }
    return cellFont;
}

From source file:org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.Sheet.java

License:Apache License

private boolean isBlank(HSSFCellStyle style) {
    HSSFFont font = null;
    if (style.getFontIndex() > 0) {
        font = (_workbook.getWorkbook().getFontAt(style.getFontIndex()));
    }// ww  w.  ja v a 2  s .  co  m
    if (style.getBorderBottom() == 0 && style.getBorderTop() == 0 && style.getBorderRight() == 0
            && style.getBorderLeft() == 0 && style.getFillBackgroundColor() == HSSFColor.WHITE.index
            && style.getFillPattern() == 0
            && (style.getFontIndex() == 0
                    || ((font.getFontName().equals("Arial") || font.getFontName().equals("Helvetica"))
                            && font.getFontHeightInPoints() > 8 && font.getFontHeightInPoints() < 12))) {
        return true;
    }
    return false;
}

From source file:org.apache.cocoon.generation.HSSFGenerator.java

License:Apache License

/**
 * Writes out the workbook data as XML, with formatting information
 *//*ww w  .ja  v  a2  s .  c o  m*/
private void writeStyles(HSSFWorkbook workbook, HSSFSheet sheet) throws SAXException {
    start("Styles");
    HSSFRow row = null;
    HSSFCell cell = null;
    Iterator cells = null;
    Iterator rows = sheet.rowIterator();
    while (rows.hasNext()) {
        row = (HSSFRow) rows.next();
        cells = row.cellIterator();
        while (cells.hasNext()) {
            cell = (HSSFCell) cells.next();
            attribute("startRow", Integer.toString(row.getRowNum()));
            attribute("endRow", Integer.toString(row.getRowNum()));
            attribute("startCol", Short.toString(cell.getCellNum()));
            attribute("endCol", Short.toString(cell.getCellNum()));
            start("StyleRegion");
            HSSFCellStyle style = cell.getCellStyle();
            attribute("HAlign", Integer.toString(style.getAlignment()));
            attribute("VAlign", Integer.toString(style.getVerticalAlignment()));
            attribute("WrapText", ((style.getWrapText()) ? "1" : "0"));
            attribute("Orient", Integer.toString(style.getRotation()));
            attribute("Indent", Integer.toString(style.getIndention()));
            attribute("Locked", ((style.getLocked()) ? "1" : "0"));
            attribute("Hidden", ((style.getHidden()) ? "1" : "0"));
            attribute("Fore",
                    workbook.getCustomPalette().getColor(style.getFillForegroundColor()).getHexString());
            attribute("Back",
                    workbook.getCustomPalette().getColor(style.getFillBackgroundColor()).getHexString());
            attribute("PatternColor", Integer.toString(style.getFillPattern())); // TODO
            attribute("Format", "General"); // TODO
            start("Style");
            HSSFFont font = workbook.getFontAt(style.getFontIndex());
            attribute("Unit", Short.toString(font.getFontHeightInPoints()));
            attribute("Bold", Short.toString(font.getBoldweight()));
            attribute("Italic", ((font.getItalic()) ? "1" : "0"));
            attribute("Unterline", Integer.toString(font.getUnderline()));
            attribute("StrikeThrough", ((font.getStrikeout()) ? "1" : "0"));
            start("Font");
            data(font.getFontName());
            end("Font");
            end("Style");
            end("StyleRegion");
        }
    }
    end("Styles");
}

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

License:Open Source License

private static String getHSSFFontString(HSSFWorkbook workbook, HSSFFont font) {
    StringBuffer sb = new StringBuffer();
    sb.append("[FONT]");
    sb.append("fontheight=").append(Integer.toHexString(font.getFontHeight())).append(",");
    sb.append("italic=").append(font.getItalic()).append(",");
    sb.append("strikout=").append(font.getStrikeout()).append(",");
    sb.append("colorpalette=").append(getHSSFColorString((HSSFWorkbook) workbook, font.getColor())).append(",");
    sb.append("boldweight=").append(font.getBold()).append(",");
    sb.append("supersubscript=").append(Integer.toHexString(font.getTypeOffset())).append(",");
    sb.append("underline=").append(Integer.toHexString(font.getUnderline())).append(",");
    sb.append("charset=").append(Integer.toHexString(font.getCharSet())).append(",");
    sb.append("fontname=").append(font.getFontName());
    sb.append("[/FONT]");
    return sb.toString();
}

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

License:Open Source License

/**
 * HSSF????//from w w w. j  a  va 2  s  . c  om
 * 
 * @param workbook 
 * @param font 
 * @return ??
 */
private static String getHSSFFontString(HSSFWorkbook workbook, HSSFFont font) {
    StringBuffer sb = new StringBuffer();
    sb.append("[FONT]");
    sb.append("fontheight=").append(Integer.toHexString(font.getFontHeight())).append(",");
    sb.append("italic=").append(font.getItalic()).append(",");
    sb.append("strikout=").append(font.getStrikeout()).append(",");
    sb.append("colorpalette=").append(getHSSFColorString((HSSFWorkbook) workbook, font.getColor())).append(",");
    sb.append("bold=").append(font.getBold()).append(",");
    sb.append("supersubscript=").append(Integer.toHexString(font.getTypeOffset())).append(",");
    sb.append("underline=").append(Integer.toHexString(font.getUnderline())).append(",");
    sb.append("charset=").append(Integer.toHexString(font.getCharSet())).append(",");
    sb.append("fontname=").append(font.getFontName());
    sb.append("[/FONT]");
    return sb.toString();
}

From source file:org.jxstar.report.util.XlsToHtml.java

/**
 * ??//from  www .j a v a2  s  .  c o m
 * @param style -- xls?
 * @return
 */
private String getFontStyle(HSSFFont font) {
    StringBuilder sbStyle = new StringBuilder();

    //???
    sbStyle.append("word-break:keep-all;");
    sbStyle.append("font-family:" + font.getFontName() + ";");
    sbStyle.append("font-size:" + font.getFontHeightInPoints() + "pt;");

    short bold = font.getBoldweight();
    if (bold == Font.BOLDWEIGHT_BOLD) {
        sbStyle.append("font-weight:bold;");
    }

    return sbStyle.toString();
}

From source file:org.orbeon.oxf.util.XLSUtils.java

License:Open Source License

public static void copyFont(HSSFFont destination, HSSFFont source) {
    destination.setBoldweight(source.getBoldweight());
    destination.setColor(source.getColor());
    destination.setFontHeight(source.getFontHeight());
    destination.setFontHeightInPoints(source.getFontHeightInPoints());
    destination.setFontName(source.getFontName());
    destination.setItalic(source.getItalic());
    destination.setStrikeout(source.getStrikeout());
    destination.setTypeOffset(source.getTypeOffset());
    destination.setUnderline(source.getUnderline());
}

From source file:org.pentaho.reporting.engine.classic.core.bugs.Prd5391.java

License:Open Source License

@Test
public void testSlowExport() throws ResourceException, ReportProcessingException, IOException {
    // This establishes a baseline for the second test using the slow export.

    final MasterReport report = DebugReportRunner.parseLocalReport("Prd-5391.prpt", Prd5391.class);
    final ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ExcelReportUtil.createXLS(report, bout);

    final HSSFWorkbook wb = new HSSFWorkbook(new ByteArrayInputStream(bout.toByteArray()));
    final HSSFSheet sheetAt = wb.getSheetAt(0);
    final HSSFRow row = sheetAt.getRow(0);
    final HSSFCell cell0 = row.getCell(0);

    // assert that we are in the correct export type ..
    final HSSFCellStyle cellStyle = cell0.getCellStyle();
    final HSSFColor fillBackgroundColorColor = cellStyle.getFillBackgroundColorColor();
    final HSSFColor fillForegroundColorColor = cellStyle.getFillForegroundColorColor();
    Assert.assertEquals("0:0:0", fillBackgroundColorColor.getHexString());
    Assert.assertEquals("FFFF:8080:8080", fillForegroundColorColor.getHexString());

    HSSFFont font = cellStyle.getFont(wb);
    Assert.assertEquals("Times New Roman", font.getFontName());
}

From source file:org.pentaho.reporting.engine.classic.core.bugs.Prd5391.java

License:Open Source License

@Test
public void testFastExport() throws ResourceException, ReportProcessingException, IOException {
    // This establishes a baseline for the second test using the slow export.

    final MasterReport report = DebugReportRunner.parseLocalReport("Prd-5391.prpt", Prd5391.class);
    final ByteArrayOutputStream bout = new ByteArrayOutputStream();
    FastExcelReportUtil.processXls(report, bout);

    final HSSFWorkbook wb = new HSSFWorkbook(new ByteArrayInputStream(bout.toByteArray()));
    final HSSFSheet sheetAt = wb.getSheetAt(0);
    final HSSFRow row = sheetAt.getRow(0);
    final HSSFCell cell0 = row.getCell(0);

    // assert that we are in the correct export type ..
    final HSSFCellStyle cellStyle = cell0.getCellStyle();
    final HSSFColor fillBackgroundColorColor = cellStyle.getFillBackgroundColorColor();
    final HSSFColor fillForegroundColorColor = cellStyle.getFillForegroundColorColor();
    Assert.assertEquals("0:0:0", fillBackgroundColorColor.getHexString());
    Assert.assertEquals("FFFF:8080:8080", fillForegroundColorColor.getHexString());

    HSSFFont font = cellStyle.getFont(wb);
    Assert.assertEquals("Times New Roman", font.getFontName());
}