List of usage examples for org.apache.poi.hssf.usermodel HSSFFont getFontHeightInPoints
public short getFontHeightInPoints()
From source file:gov.nih.nci.evs.browser.utils.ResolvedValueSetIteratorHolder.java
License:Open Source License
private void td(final HSSFCell cell, StringBuffer buf) { int colspan = 1; if (colIndex == mergeStart) { // First cell in the merging region - set colspan. colspan = mergeEnd - mergeStart + 1; } else if (colIndex == mergeEnd) { // Last cell in the merging region - no more skipped cells. mergeStart = -1;/*from w w w .j ava 2 s . c o m*/ mergeEnd = -1; return; } else if (mergeStart != -1 && mergeEnd != -1 && colIndex > mergeStart && colIndex < mergeEnd) { // Within the merging region - skip the cell. return; } //KLO 05022018 //buf.append("<td "); buf.append("<td height=\"15\" "); if (colspan > 1) { buf.append("colspan='").append(colspan).append("' "); } if (cell == null) { buf.append("/>"); return; } buf.append("style='"); final HSSFCellStyle style = cell.getCellStyle(); // Text alignment switch (style.getAlignment()) { case CellStyle.ALIGN_LEFT: buf.append("text-align: left; "); break; case CellStyle.ALIGN_RIGHT: buf.append("text-align: right; "); break; case CellStyle.ALIGN_CENTER: buf.append("text-align: center; "); break; default: break; } // Font style, size and weight final HSSFFont font = style.getFont(book); if (font == null) return; if (font.getBoldweight() == HSSFFont.BOLDWEIGHT_BOLD) { buf.append("font-weight: bold; "); } if (font.getItalic()) { buf.append("font-style: italic; "); } if (font.getUnderline() != HSSFFont.U_NONE) { buf.append("text-decoration: underline; "); } buf.append("font-size: ").append(Math.floor(font.getFontHeightInPoints() * 0.8)).append("pt; "); // Cell background and font colours final short[] backRGB = style.getFillForegroundColorColor().getTriplet(); final HSSFColor foreColor = palette.getColor(font.getColor()); if (foreColor != null) { final short[] foreRGB = foreColor.getTriplet(); if (foreRGB[0] != 0 || foreRGB[1] != 0 || foreRGB[2] != 0) { buf.append("color: rgb(").append(foreRGB[0]).append(',').append(foreRGB[1]).append(',') .append(foreRGB[2]).append(");"); } } if (backRGB[0] != 0 || backRGB[1] != 0 || backRGB[2] != 0) { buf.append("background-color: rgb(").append(backRGB[0]).append(',').append(backRGB[1]).append(',') .append(backRGB[2]).append(");"); } // Border if (style.getBorderTop() != HSSFCellStyle.BORDER_NONE) { buf.append("border-top-style: solid; "); } if (style.getBorderRight() != HSSFCellStyle.BORDER_NONE) { buf.append("border-right-style: solid; "); } if (style.getBorderBottom() != HSSFCellStyle.BORDER_NONE) { buf.append("border-bottom-style: solid; "); } if (style.getBorderLeft() != HSSFCellStyle.BORDER_NONE) { buf.append("border-left-style: solid; "); } buf.append("'>"); String val = ""; try { switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_STRING: val = cell.getStringCellValue(); break; case HSSFCell.CELL_TYPE_NUMERIC: // POI does not distinguish between integer and double, thus: final double original = cell.getNumericCellValue(), rounded = Math.round(original); if (Math.abs(rounded - original) < 0.00000000000000001) { val = String.valueOf((int) rounded); } else { val = String.valueOf(original); } break; case HSSFCell.CELL_TYPE_FORMULA: final CellValue cv = evaluator.evaluate(cell); if (cv == null) return; switch (cv.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: buf.append(cv.getBooleanValue()); break; case Cell.CELL_TYPE_NUMERIC: buf.append(cv.getNumberValue()); break; case Cell.CELL_TYPE_STRING: buf.append(cv.getStringValue()); break; case Cell.CELL_TYPE_BLANK: break; case Cell.CELL_TYPE_ERROR: break; default: break; } break; default: // Neither string or number? Could be a date. try { val = sdf.format(cell.getDateCellValue()); } catch (final Exception e1) { } } } catch (final Exception e) { val = e.getMessage(); } if ("null".equals(val)) { val = ""; } if (pix.containsKey(rowIndex)) { if (pix.get(rowIndex).containsKey(colIndex)) { for (final HSSFPictureData pic : pix.get(rowIndex).get(colIndex)) { buf.append("<img alt='Image in Excel sheet' src='data:"); buf.append(pic.getMimeType()); buf.append(";base64,"); try { buf.append(new String(Base64.encodeBase64(pic.getData()), "US-ASCII")); } catch (final UnsupportedEncodingException e) { throw new RuntimeException(e); } buf.append("'/>"); } } } if (isCode(val) && this.URL != null) { val = getHyperLink(val); } buf.append(val); buf.append("</td>"); }
From source file:net.sf.jasperreports.engine.export.JRXlsExporter.java
License:Open Source License
/** * *//* w w w .j a va 2 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; } } 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
/** * *//*from w ww.j a v a 2 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())); }/*from w ww. j a v a 2 s .c o 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 *///from ww w . j a v a 2 s .co 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.jxstar.report.util.XlsToHtml.java
/** * ??//from w w w . j av a2s . 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.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 . j a v a 2s . com }
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();/* w ww . jav a 2s. 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.j a va 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; }