Java Code Examples for org.apache.poi.ss.usermodel.Font#setUnderline()
The following examples show how to use
org.apache.poi.ss.usermodel.Font#setUnderline() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExcelFontFactory.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 7 votes |
/** * Returns the excel font stored in this wrapper. * * @param wrapper * the font wrapper that holds all font information from the repagination. * @return the created font. */ private Font createFont( final HSSFFontWrapper wrapper ) { final Font font = workbook.createFont(); font.setBold( wrapper.isBold() ); font.setColor( wrapper.getColorIndex() ); font.setFontName( wrapper.getFontName() ); font.setFontHeightInPoints( (short) wrapper.getFontHeight() ); font.setItalic( wrapper.isItalic() ); font.setStrikeout( wrapper.isStrikethrough() ); if ( wrapper.isUnderline() ) { font.setUnderline( Font.U_SINGLE ); } else { font.setUnderline( Font.U_NONE ); } return font; }
Example 2
Source File: AbstractStyleBuilder.java From bdf3 with Apache License 2.0 | 6 votes |
public void setCellStyleFont(Workbook workbook, CellStyle style, int i) { Font font = workbook.createFont(); if (i == 0) { // 正常 } else if (i == 4) { // 下划线 font.setUnderline(Font.U_SINGLE); style.setFont(font); } else if (i == 2) { // 倾斜 font.setItalic(true); style.setFont(font); } else if (i == 1) { // 加粗 font.setBoldweight(Font.BOLDWEIGHT_BOLD); style.setFont(font); } }
Example 3
Source File: LinkDefaultCellStyle.java From myexcel with Apache License 2.0 | 5 votes |
@Override public CellStyle supply(Workbook workbook) { CellStyle linkStyle = workbook.createCellStyle(); Font linkFont = workbook.createFont(); linkFont.setUnderline(Font.U_SINGLE); linkFont.setColor(IndexedColors.BLUE.getIndex()); linkStyle.setFont(linkFont); linkStyle.setAlignment(HorizontalAlignment.CENTER); linkStyle.setVerticalAlignment(VerticalAlignment.CENTER); linkStyle.setBorderBottom(BorderStyle.THIN); linkStyle.setBorderRight(BorderStyle.THIN); linkStyle.setBorderLeft(BorderStyle.THIN); linkStyle.setBorderTop(BorderStyle.THIN); return linkStyle; }
Example 4
Source File: ExportTimetableXLS.java From unitime with Apache License 2.0 | 5 votes |
protected Font getFont(boolean bold, boolean italic, boolean underline, Color c) { Short color = null; if (c == null) c = Color.BLACK; if (c != null) { String colorId = Integer.toHexString(c.getRGB()); color = iColors.get(colorId); if (color == null) { HSSFPalette palette = ((HSSFWorkbook)iWorkbook).getCustomPalette(); HSSFColor clr = palette.findSimilarColor(c.getRed(), c.getGreen(), c.getBlue()); color = (clr == null ? IndexedColors.BLACK.getIndex() : clr.getIndex()); iColors.put(colorId, color); } } String fontId = (bold ? "b" : "") + (italic ? "i" : "") + (underline ? "u" : "") + (color == null ? "" : color); Font font = iFonts.get(fontId); if (font == null) { font = iWorkbook.createFont(); font.setBold(bold); font.setItalic(italic); font.setUnderline(underline ? Font.U_SINGLE : Font.U_NONE); font.setColor(color); font.setFontHeightInPoints((short)iFontSize); font.setFontName(iFontName); iFonts.put(fontId, font); } return font; }
Example 5
Source File: XLSPrinter.java From unitime with Apache License 2.0 | 5 votes |
protected Font getFont(boolean bold, boolean italic, boolean underline, Color c) { Short color = null; if (c == null) c = Color.BLACK; if (c != null) { String colorId = Integer.toHexString(c.getRGB()); color = iColors.get(colorId); if (color == null) { HSSFPalette palette = ((HSSFWorkbook)iWorkbook).getCustomPalette(); HSSFColor clr = palette.findSimilarColor(c.getRed(), c.getGreen(), c.getBlue()); color = (clr == null ? IndexedColors.BLACK.getIndex() : clr.getIndex()); iColors.put(colorId, color); } } String fontId = (bold ? "b" : "") + (italic ? "i" : "") + (underline ? "u" : "") + (color == null ? "" : color); Font font = iFonts.get(fontId); if (font == null) { font = iWorkbook.createFont(); font.setBold(bold); font.setItalic(italic); font.setUnderline(underline ? Font.U_SINGLE : Font.U_NONE); font.setColor(color); font.setFontHeightInPoints((short)10); font.setFontName("Arial"); iFonts.put(fontId, font); } return font; }
Example 6
Source File: ExcelStyle.java From objectlabkit with Apache License 2.0 | 5 votes |
private void addFontFormat(ExcelCell cell, CellStyle cellStyle) { if (bold || italic || underline || header || fontColour != null || strikeout) { Font f = cell.workbook().createFont(); f.setBold(bold || header); if (underline) { f.setUnderline(Font.U_SINGLE); } if (fontColour != null) { f.setColor(fontColour.getIndex()); } f.setItalic(italic); f.setStrikeout(strikeout); cellStyle.setFont(f); } }
Example 7
Source File: FontManager.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * Create a new POI Font based upon a BIRT style. * @param birtStyle * The BIRT style to base the Font upon. * @return * The Font whose attributes are described by the BIRT style. */ private Font createFont(BirtStyle birtStyle) { Font font = workbook.createFont(); // Family String fontName = smu.poiFontNameFromBirt(cleanupQuotes(birtStyle.getProperty( StyleConstants.STYLE_FONT_FAMILY ))); if( fontName == null ) { fontName = "Calibri"; } font.setFontName(fontName); // Size short fontSize = smu.fontSizeInPoints(cleanupQuotes(birtStyle.getProperty( StyleConstants.STYLE_FONT_SIZE ))); if(fontSize > 0) { font.setFontHeightInPoints(fontSize); } // Weight short fontWeight = smu.poiFontWeightFromBirt(cleanupQuotes(birtStyle.getProperty( StyleConstants.STYLE_FONT_WEIGHT ))); if(fontWeight > 0) { font.setBoldweight(fontWeight); } // Style String fontStyle = cleanupQuotes(birtStyle.getProperty( StyleConstants.STYLE_FONT_STYLE ) ); if( CSSConstants.CSS_ITALIC_VALUE.equals(fontStyle) || CSSConstants.CSS_OBLIQUE_VALUE.equals(fontStyle)) { font.setItalic(true); } // Underline String fontUnderline = cleanupQuotes(birtStyle.getProperty( StyleConstants.STYLE_TEXT_UNDERLINE ) ); if( CSSConstants.CSS_UNDERLINE_VALUE.equals(fontUnderline) ) { font.setUnderline(FontUnderline.SINGLE.getByteValue()); } // Colour smu.addColourToFont( workbook, font, cleanupQuotes( birtStyle.getProperty( StyleConstants.STYLE_COLOR ) ) ); fonts.add(new FontPair(birtStyle, font)); return font; }
Example 8
Source File: StyleUtil.java From easyexcel with Apache License 2.0 | 4 votes |
private static void buildFont(Workbook workbook, CellStyle cellStyle, WriteFont writeFont, boolean isHead) { Font font = null; if (isHead) { font = workbook.createFont(); font.setFontName("宋体"); font.setFontHeightInPoints((short)14); font.setBold(true); cellStyle.setFont(font); } if (writeFont == null) { return; } if (!isHead) { font = workbook.createFont(); cellStyle.setFont(font); } if (writeFont.getFontName() != null) { font.setFontName(writeFont.getFontName()); } if (writeFont.getFontHeightInPoints() != null) { font.setFontHeightInPoints(writeFont.getFontHeightInPoints()); } if (writeFont.getItalic() != null) { font.setItalic(writeFont.getItalic()); } if (writeFont.getStrikeout() != null) { font.setStrikeout(writeFont.getStrikeout()); } if (writeFont.getColor() != null) { font.setColor(writeFont.getColor()); } if (writeFont.getTypeOffset() != null) { font.setTypeOffset(writeFont.getTypeOffset()); } if (writeFont.getUnderline() != null) { font.setUnderline(writeFont.getUnderline()); } if (writeFont.getCharset() != null) { font.setCharSet(writeFont.getCharset()); } if (writeFont.getBold() != null) { font.setBold(writeFont.getBold()); } }
Example 9
Source File: FontStyle.java From myexcel with Apache License 2.0 | 4 votes |
public static Font getFont(Map<String, String> style, Map<String, Font> fontMap, Supplier<Font> fontSupplier, CustomColor customColor) { String cacheKey = getCacheKey(style); if (fontMap.get(cacheKey) != null) { return fontMap.get(cacheKey); } Font font = null; String fs = style.get(FONT_SIZE); if (fs != null) { short fontSize = (short) TdUtil.getValue(fs); font = fontSupplier.get(); font.setFontHeightInPoints(fontSize); } String fontFamily = style.get(FONT_FAMILY); if (fontFamily != null) { font = createFontIfNull(fontSupplier, font); font.setFontName(fontFamily); } String italic = style.get(FONT_STYLE); if (ITALIC.equals(italic)) { font = createFontIfNull(fontSupplier, font); font.setItalic(true); } String textDecoration = style.get(TEXT_DECORATION); if (LINE_THROUGH.equals(textDecoration)) { font = createFontIfNull(fontSupplier, font); font.setStrikeout(true); } else if (UNDERLINE.equals(textDecoration)) { font = createFontIfNull(fontSupplier, font); font.setUnderline(Font.U_SINGLE); } String fontWeight = style.get(FONT_WEIGHT); if (BOLD.equals(fontWeight)) { font = createFontIfNull(fontSupplier, font); font.setBold(true); } String fontColor = style.get(FONT_COLOR); if (StringUtil.isNotBlank(fontColor)) { font = createFontIfNull(fontSupplier, font); font = setFontColor(font, customColor, fontColor); } if (font != null) { fontMap.put(cacheKey, font); } return font; }
Example 10
Source File: Util.java From Knowage-Server with GNU Affero General Public License v3.0 | 4 votes |
private static void copyCell(Cell oldCell, Cell newCell, List<CellStyle> styleList) { if (styleList != null) { if (oldCell.getSheet().getWorkbook() == newCell.getSheet().getWorkbook()) { newCell.setCellStyle(oldCell.getCellStyle()); } else { DataFormat newDataFormat = newCell.getSheet().getWorkbook().createDataFormat(); CellStyle newCellStyle = getSameCellStyle(oldCell, newCell, styleList); if (newCellStyle == null) { Font oldFont = oldCell.getSheet().getWorkbook().getFontAt(oldCell.getCellStyle().getFontIndex()); Font newFont = newCell.getSheet().getWorkbook().findFont(oldFont.getBoldweight(), oldFont.getColor(), oldFont.getFontHeight(), oldFont.getFontName(), oldFont.getItalic(), oldFont.getStrikeout(), oldFont.getTypeOffset(), oldFont.getUnderline()); if (newFont == null) { newFont = newCell.getSheet().getWorkbook().createFont(); newFont.setBoldweight(oldFont.getBoldweight()); newFont.setColor(oldFont.getColor()); newFont.setFontHeight(oldFont.getFontHeight()); newFont.setFontName(oldFont.getFontName()); newFont.setItalic(oldFont.getItalic()); newFont.setStrikeout(oldFont.getStrikeout()); newFont.setTypeOffset(oldFont.getTypeOffset()); newFont.setUnderline(oldFont.getUnderline()); newFont.setCharSet(oldFont.getCharSet()); } short newFormat = newDataFormat.getFormat(oldCell.getCellStyle().getDataFormatString()); newCellStyle = newCell.getSheet().getWorkbook().createCellStyle(); newCellStyle.setFont(newFont); newCellStyle.setDataFormat(newFormat); newCellStyle.setAlignment(oldCell.getCellStyle().getAlignment()); newCellStyle.setHidden(oldCell.getCellStyle().getHidden()); newCellStyle.setLocked(oldCell.getCellStyle().getLocked()); newCellStyle.setWrapText(oldCell.getCellStyle().getWrapText()); newCellStyle.setBorderBottom(oldCell.getCellStyle().getBorderBottom()); newCellStyle.setBorderLeft(oldCell.getCellStyle().getBorderLeft()); newCellStyle.setBorderRight(oldCell.getCellStyle().getBorderRight()); newCellStyle.setBorderTop(oldCell.getCellStyle().getBorderTop()); newCellStyle.setBottomBorderColor(oldCell.getCellStyle().getBottomBorderColor()); newCellStyle.setFillBackgroundColor(oldCell.getCellStyle().getFillBackgroundColor()); newCellStyle.setFillForegroundColor(oldCell.getCellStyle().getFillForegroundColor()); newCellStyle.setFillPattern(oldCell.getCellStyle().getFillPattern()); newCellStyle.setIndention(oldCell.getCellStyle().getIndention()); newCellStyle.setLeftBorderColor(oldCell.getCellStyle().getLeftBorderColor()); newCellStyle.setRightBorderColor(oldCell.getCellStyle().getRightBorderColor()); newCellStyle.setRotation(oldCell.getCellStyle().getRotation()); newCellStyle.setTopBorderColor(oldCell.getCellStyle().getTopBorderColor()); newCellStyle.setVerticalAlignment(oldCell.getCellStyle().getVerticalAlignment()); styleList.add(newCellStyle); } newCell.setCellStyle(newCellStyle); } } switch (oldCell.getCellType()) { case Cell.CELL_TYPE_STRING: newCell.setCellValue(oldCell.getStringCellValue()); break; case Cell.CELL_TYPE_NUMERIC: newCell.setCellValue(oldCell.getNumericCellValue()); break; case Cell.CELL_TYPE_BLANK: newCell.setCellType(Cell.CELL_TYPE_BLANK); break; case Cell.CELL_TYPE_BOOLEAN: newCell.setCellValue(oldCell.getBooleanCellValue()); break; case Cell.CELL_TYPE_ERROR: newCell.setCellErrorValue(oldCell.getErrorCellValue()); break; case Cell.CELL_TYPE_FORMULA: newCell.setCellFormula(oldCell.getCellFormula()); formulaInfoList.add(new FormulaInfo(oldCell.getSheet().getSheetName(), oldCell.getRowIndex(), oldCell.getColumnIndex(), oldCell.getCellFormula())); break; default: break; } }
Example 11
Source File: SpreadSheetFormatOptions.java From openbd-core with GNU General Public License v3.0 | 4 votes |
public static Font createCommentFont( Workbook workbook, cfStructData _struct ) throws Exception { Font font = workbook.createFont(); if ( _struct.containsKey("bold") ){ if ( _struct.getData("bold").getBoolean() ) font.setBoldweight( Font.BOLDWEIGHT_BOLD ); else font.setBoldweight( Font.BOLDWEIGHT_NORMAL ); } if ( _struct.containsKey("color") ){ String v = _struct.getData("color").getString(); Short s = lookup_colors.get( v ); if ( s == null ){ throw new Exception( "invalid parameter for 'color' (" + v + ")" ); }else font.setColor( s ); } if ( _struct.containsKey("font") ){ font.setFontName( _struct.getData("font").getString() ); } if ( _struct.containsKey("italic") ){ font.setItalic( _struct.getData("italic").getBoolean() ); } if ( _struct.containsKey("strikeout") ){ font.setStrikeout( _struct.getData("strikeout").getBoolean() ); } if ( _struct.containsKey("underline") ){ font.setUnderline( (byte)_struct.getData("underline").getInt() ); } if ( _struct.containsKey("size") ){ font.setFontHeightInPoints( (short)_struct.getData("size").getInt() ); } return font; }