Java Code Examples for org.apache.poi.ss.usermodel.Font#setStrikeout()

The following examples show how to use org.apache.poi.ss.usermodel.Font#setStrikeout() . 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 vote down vote up
/**
 * 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: ExcelStyle.java    From objectlabkit with Apache License 2.0 5 votes vote down vote up
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 3
Source File: StyleUtil.java    From easyexcel with Apache License 2.0 4 votes vote down vote up
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 4
Source File: FontStyle.java    From myexcel with Apache License 2.0 4 votes vote down vote up
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 5
Source File: Util.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
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 6
Source File: SpreadSheetFormatOptions.java    From openbd-core with GNU General Public License v3.0 4 votes vote down vote up
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;
}