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:org.pentaho.reporting.engine.classic.core.bugs.Prd5391IT.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", Prd5391IT.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.Prd5391IT.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", Prd5391IT.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());
}

From source file:org.sysmodb.xml.HSSFXMLStyleHelper.java

License:BSD License

public boolean areFontsEmpty(CellStyle style) {
    HSSFCellStyle newStyle = (HSSFCellStyle) style;
    HSSFFont font = newStyle.getFont(workbook);
    if (font.getBold())
        return false;
    if (font.getItalic())
        return false;
    if (font.getUnderline() != HSSFFont.U_NONE)
        return false;
    // Ignore same-ish defaults
    if (font.getFontHeightInPoints() != 10 && font.getFontHeightInPoints() != 11)
        return false;
    // Arial is default for Excel, Calibri is default for OO
    if (!font.getFontName().equals("Arial") && !font.getFontName().equals("Calibri"))
        return false;
    if ((font.getColor() != HSSFFont.COLOR_NORMAL) && (getRGBString(font.getColor()) != null)
            && !getRGBString(font.getColor()).equals("#000"))
        return false;

    return true;//  w w  w . ja va 2 s.c  o  m
}

From source file:org.sysmodb.xml.HSSFXMLStyleHelper.java

License:BSD License

@Override
public void writeFontProperties(XMLStreamWriter xmlWriter, CellStyle style) throws XMLStreamException {
    HSSFCellStyle newStyle = (HSSFCellStyle) style;
    HSSFFont font = newStyle.getFont(workbook);
    if (font.getBold()) {
        xmlWriter.writeStartElement("font-weight");
        xmlWriter.writeCharacters("bold");
        xmlWriter.writeEndElement();//from   w ww  .j a va2 s  .  co  m
    }
    if (font.getItalic()) {
        xmlWriter.writeStartElement("font-style");
        xmlWriter.writeCharacters("italics");
        xmlWriter.writeEndElement();
    }
    if (font.getUnderline() != HSSFFont.U_NONE) {
        xmlWriter.writeStartElement("text-decoration");
        xmlWriter.writeCharacters("underline");
        xmlWriter.writeEndElement();
    }
    // Ignore same-ish defaults
    if (font.getFontHeightInPoints() != 10 && font.getFontHeightInPoints() != 11) {
        xmlWriter.writeStartElement("font-size");
        xmlWriter.writeCharacters(String.valueOf(font.getFontHeightInPoints() + "pt"));
        xmlWriter.writeEndElement();
    }
    // Arial is default for Excel, Calibri is default for OO
    if (!font.getFontName().equals("Arial") && !font.getFontName().equals("Calibri")) {
        xmlWriter.writeStartElement("font-family");
        xmlWriter.writeCharacters(font.getFontName());
        xmlWriter.writeEndElement();
    }
    if ((font.getColor() != HSSFFont.COLOR_NORMAL) && (getRGBString(font.getColor()) != null)
            && !getRGBString(font.getColor()).equals("#000")) {
        xmlWriter.writeStartElement("color");
        xmlWriter.writeCharacters(getRGBString(font.getColor()));
        xmlWriter.writeEndElement();
    }

}

From source file:poi.hssf.view.SVTableCellEditor.java

License:Apache License

/**
 *  Gets the tableCellEditorComponent attribute of the SVTableCellEditor object
 *
 * @return             The tableCellEditorComponent value
 *//*from  w ww  . ja v a 2  s.  c om*/
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row,
        int column) {
    System.out.println("GetTableCellEditorComponent");
    HSSFCell cell = (HSSFCell) value;
    if (cell != null) {
        HSSFCellStyle style = cell.getCellStyle();
        HSSFFont f = wb.getFontAt(style.getFontIndex());
        boolean isbold = f.getBoldweight() > HSSFFont.BOLDWEIGHT_NORMAL;
        boolean isitalics = f.getItalic();

        int fontstyle = Font.PLAIN;

        if (isbold)
            fontstyle = Font.BOLD;
        if (isitalics)
            fontstyle = fontstyle | Font.ITALIC;

        int fontheight = f.getFontHeightInPoints();
        if (fontheight == 9)
            fontheight = 10; //fix for stupid ol Windows

        Font font = new Font(f.getFontName(), fontstyle, fontheight);
        editor.setFont(font);

        if (style.getFillPattern() == HSSFCellStyle.SOLID_FOREGROUND) {
            editor.setBackground(getAWTColor(style.getFillForegroundColor(), white));
        } else
            editor.setBackground(white);

        editor.setForeground(getAWTColor(f.getColor(), black));

        //Set the value that is rendered for the cell
        switch (cell.getCellType()) {
        case HSSFCell.CELL_TYPE_BLANK:
            editor.setText("");
            break;
        case HSSFCell.CELL_TYPE_BOOLEAN:
            if (cell.getBooleanCellValue()) {
                editor.setText("true");
            } else {
                editor.setText("false");
            }
            break;
        case HSSFCell.CELL_TYPE_NUMERIC:
            editor.setText(Double.toString(cell.getNumericCellValue()));
            break;
        case HSSFCell.CELL_TYPE_STRING:
            editor.setText(cell.getRichStringCellValue().getString());
            break;
        case HSSFCell.CELL_TYPE_FORMULA:
        default:
            editor.setText("?");
        }
        switch (style.getAlignment()) {
        case HSSFCellStyle.ALIGN_LEFT:
        case HSSFCellStyle.ALIGN_JUSTIFY:
        case HSSFCellStyle.ALIGN_FILL:
            editor.setHorizontalAlignment(SwingConstants.LEFT);
            break;
        case HSSFCellStyle.ALIGN_CENTER:
        case HSSFCellStyle.ALIGN_CENTER_SELECTION:
            editor.setHorizontalAlignment(SwingConstants.CENTER);
            break;
        case HSSFCellStyle.ALIGN_GENERAL:
        case HSSFCellStyle.ALIGN_RIGHT:
            editor.setHorizontalAlignment(SwingConstants.RIGHT);
            break;
        default:
            editor.setHorizontalAlignment(SwingConstants.LEFT);
            break;
        }

    }
    return editor;
}

From source file:poi.hssf.view.SVTableUtils.java

License:Apache License

/**
 *  Creates a new font for a specific cell style
 */// ww w. java 2  s.  c  o  m
public static Font makeFont(HSSFFont font) {
    boolean isbold = font.getBoldweight() > HSSFFont.BOLDWEIGHT_NORMAL;
    boolean isitalics = font.getItalic();
    int fontstyle = Font.PLAIN;
    if (isbold) {
        fontstyle = Font.BOLD;
    }
    if (isitalics) {
        fontstyle = fontstyle | Font.ITALIC;
    }

    int fontheight = font.getFontHeightInPoints();
    if (fontheight == 9) {
        //fix for stupid ol Windows
        fontheight = 10;
    }

    return new Font(font.getFontName(), fontstyle, fontheight);
}

From source file:uk.ac.manchester.cs.owl.semspreadsheets.model.hssf.impl.CellHSSFImpl.java

License:BSD License

private Font getFont(HSSFFont hssfFont) {
    Font font = fontCache.get(hssfFont);
    if (font == null) {
        String name = hssfFont.getFontName();
        int size = hssfFont.getFontHeightInPoints();
        int style = Font.PLAIN;
        if (hssfFont.getBoldweight() == HSSFFont.BOLDWEIGHT_BOLD) {
            style = Font.BOLD;/*  w  w w  .  j a v a 2  s.  co  m*/
            if (hssfFont.getItalic()) {
                style = style | Font.ITALIC;
            }
        } else if (hssfFont.getItalic()) {
            style = Font.ITALIC;
        }
        font = new Font(name, style, size);
        fontCache.put(hssfFont, font);
    }
    return font;

}