private HSSFFont matchFont( Font matchFont ) { HSSFColor hssfColor = workbook.getCustomPalette() .findColor((byte)foreground.getRed(), (byte)foreground.getGreen(), (byte)foreground.getBlue()); if (hssfColor == null) hssfColor = workbook.getCustomPalette().findSimilarColor((byte)foreground.getRed(), (byte)foreground.getGreen(), (byte)foreground.getBlue()); boolean bold = (matchFont.getStyle() & Font.BOLD) != 0; boolean italic = (matchFont.getStyle() & Font.ITALIC) != 0; HSSFFont hssfFont = workbook.findFont(bold, hssfColor.getIndex(), (short)(matchFont.getSize() * 20), matchFont.getName(), italic, false, (short)0, (byte)0); if (hssfFont == null) { hssfFont = workbook.createFont(); hssfFont.setBold(bold); hssfFont.setColor(hssfColor.getIndex()); hssfFont.setFontHeight((short)(matchFont.getSize() * 20)); hssfFont.setFontName(matchFont.getName()); hssfFont.setItalic(italic); hssfFont.setStrikeout(false); hssfFont.setTypeOffset((short) 0); hssfFont.setUnderline((byte) 0); } return hssfFont; }
private HSSFFont matchFont( Font font ) { HSSFColor hssfColor = workbook.getCustomPalette() .findColor((byte)foreground.getRed(), (byte)foreground.getGreen(), (byte)foreground.getBlue()); if (hssfColor == null) hssfColor = workbook.getCustomPalette().findSimilarColor((byte)foreground.getRed(), (byte)foreground.getGreen(), (byte)foreground.getBlue()); boolean bold = (font.getStyle() & Font.BOLD) != 0; boolean italic = (font.getStyle() & Font.ITALIC) != 0; HSSFFont hssfFont = workbook.findFont(bold ? HSSFFont.BOLDWEIGHT_BOLD : 0, hssfColor.getIndex(), (short)(font.getSize() * 20), font.getName(), italic, false, (short)0, (byte)0); if (hssfFont == null) { hssfFont = workbook.createFont(); hssfFont.setBoldweight(bold ? HSSFFont.BOLDWEIGHT_BOLD : 0); hssfFont.setColor(hssfColor.getIndex()); hssfFont.setFontHeight((short)(font.getSize() * 20)); hssfFont.setFontName(font.getName()); hssfFont.setItalic(italic); hssfFont.setStrikeout(false); hssfFont.setTypeOffset((short) 0); hssfFont.setUnderline((byte) 0); } return hssfFont; }
private HSSFFont matchFont( Font matchFont ) { HSSFColor hssfColor = workbook.getCustomPalette() .findColor((byte)foreground.getRed(), (byte)foreground.getGreen(), (byte)foreground.getBlue()); if (hssfColor == null) hssfColor = workbook.getCustomPalette().findSimilarColor((byte)foreground.getRed(), (byte)foreground.getGreen(), (byte)foreground.getBlue()); boolean bold = (matchFont.getStyle() & Font.BOLD) != 0; boolean italic = (matchFont.getStyle() & Font.ITALIC) != 0; HSSFFont hssfFont = workbook.findFont(bold, hssfColor.getIndex(), (short)(matchFont.getSize() * 20), matchFont.getName(), italic, false, (short)0, (byte)0); if (hssfFont == null) { hssfFont = workbook.createFont(); hssfFont.setBold(bold); hssfFont.setColor(hssfColor.getIndex()); hssfFont.setFontHeight((short)(matchFont.getSize() * 20)); hssfFont.setFontName(matchFont.getName()); hssfFont.setItalic(italic); hssfFont.setStrikeout(false); hssfFont.setTypeOffset((short) 0); hssfFont.setUnderline((byte) 0); } return hssfFont; }
private HSSFFont matchFont( Font font ) { HSSFColor hssfColor = workbook.getCustomPalette() .findColor((byte)foreground.getRed(), (byte)foreground.getGreen(), (byte)foreground.getBlue()); if (hssfColor == null) hssfColor = workbook.getCustomPalette().findSimilarColor((byte)foreground.getRed(), (byte)foreground.getGreen(), (byte)foreground.getBlue()); boolean bold = (font.getStyle() & Font.BOLD) != 0; boolean italic = (font.getStyle() & Font.ITALIC) != 0; HSSFFont hssfFont = workbook.findFont(bold ? HSSFFont.BOLDWEIGHT_BOLD : 0, hssfColor.getIndex(), (short)(font.getSize() * 20), font.getName(), italic, false, (short)0, (byte)0); if (hssfFont == null) { hssfFont = workbook.createFont(); hssfFont.setBoldweight(bold ? HSSFFont.BOLDWEIGHT_BOLD : 0); hssfFont.setColor(hssfColor.getIndex()); hssfFont.setFontHeight((short)(font.getSize() * 20)); hssfFont.setFontName(font.getName()); hssfFont.setItalic(italic); hssfFont.setStrikeout(false); hssfFont.setTypeOffset((short) 0); hssfFont.setUnderline((byte) 0); } return hssfFont; }
public static void main(String[] args) throws IOException { try (HSSFWorkbook wb = new HSSFWorkbook()) { HSSFSheet sheet = wb.createSheet("new sheet"); // Create a row and put some cells in it. Rows are 0 based. HSSFRow row = sheet.createRow(1); // Create a new font and alter it. HSSFFont font = wb.createFont(); font.setFontHeightInPoints((short) 24); font.setFontName("Courier New"); font.setItalic(true); font.setStrikeout(true); // Fonts are set into a style so create a new one to use. HSSFCellStyle style = wb.createCellStyle(); style.setFont(font); // Create a cell and put a value in it. HSSFCell cell = row.createCell(1); cell.setCellValue("This is a test of fonts"); cell.setCellStyle(style); // Write the output to a file try (FileOutputStream fileOut = new FileOutputStream("workbook.xls")) { wb.write(fileOut); } } } }
fontNew.setFontHeight(fontOld.getFontHeight()); fontNew.setItalic(fontOld.getItalic()); fontNew.setStrikeout(fontOld.getStrikeout()); fontNew.setTypeOffset(fontOld.getTypeOffset()); fontNew.setUnderline(fontOld.getUnderline());
cellFont.setStrikeout(true);
newFont.setStrikeout(cellFont.getStrikeout()); newFont.setTypeOffset(cellFont.getTypeOffset()); newFont.setBold(cellFont.getBold());
newFont.setStrikeout(cellFont.getStrikeout()); newFont.setTypeOffset(cellFont.getTypeOffset()); newFont.setBoldweight(cellFont.getBoldweight());