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; }
protected void createFonts() { stdFont = wb.createFont(); boldFont = wb.createFont(); boldFont.setBold(true); }
protected void createCellStyle() { HSSFFont boldFont = wb.createFont(); boldFont.setBold(true); boldStyle = wb.createCellStyle(); boldStyle.setFont(boldFont); }
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; }
font.setFontHeightInPoints((short)12); font.setFontName("Arial"); font.setBold(true);
font.setBold(bold);
InputStream inp; HSSFWorkbook wb = null; HSSFSheet sheet = null; HSSFRow hssf_DataRow; HSSFCell cell = null; inp = new FileInputStream(FileName); wb = new HSSFWorkbook(inp); sheet = wb.getSheetAt(1); hssf_DataRow = sheet.createRow((short) 1); cell = hssf_DataRow.createCell(1); HSSFFont font = (HSSFFont) sheet.getWorkbook().createFont(); HSSFCellStyle style = (HSSFCellStyle) cell.getCellStyle(); font.setBold(true); style.setFont(font); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFillForegroundColor(new HSSFColor.BLUE().getIndex()); cell.setCellStyle(style);
/** * Obtain the style used to render a header or footer. * @return The style used to render a header or footer. */ private HSSFCellStyle getHeaderFooterStyle() { HSSFCellStyle style = this.wb.createCellStyle(); HSSFFont bold = this.wb.createFont(); bold.setBold(true); style.setBorderBottom(BorderStyle.THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); style.setFont(bold); return style; }
HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("FirstSheet"); HSSFRow rowhead = sheet.createRow(0); HSSFCellStyle style = wb.createCellStyle(); HSSFFont font = wb.createFont(); font.setFontName(HSSFFont.FONT_ARIAL); font.setFontHeightInPoints((short)10); font.setBold(true); style.setFont(font); rowhead.createCell(0).setCellValue("ID"); rowhead.createCell(1).setCellValue("First"); rowhead.createCell(2).setCellValue("Second"); rowhead.createCell(3).setCellValue("Third"); for(int j = 0; j<=3; j++) rowhead.getCell(j).setCellStyle(style);
/** * Templated method that is called for all header cells. * * @param wb the wb * @param headerCell the header cell * @return the HSSF cell style */ public HSSFCellStyle createHeaderStyle(HSSFWorkbook wb, HeaderCell headerCell) { HSSFCellStyle headerStyle = getNewCellStyle(); headerStyle.setFillPattern(FillPatternType.FINE_DOTS); headerStyle.setFillBackgroundColor(HSSFColorPredefined.BLUE_GREY.getIndex()); HSSFFont bold = wb.createFont(); bold.setBold(true); bold.setColor(HSSFColorPredefined.WHITE.getIndex()); headerStyle.setFont(bold); return headerStyle; }
boldFont.setBold(true);
/** * @see org.displaytag.render.TableWriterTemplate#writeCaption(org.displaytag.model.TableModel) */ @Override protected void writeCaption(TableModel model) throws Exception { HSSFCellStyle style = this.wb.createCellStyle(); HSSFFont bold = this.wb.createFont(); bold.setBold(true); bold.setFontHeightInPoints((short) 14); style.setFont(bold); style.setAlignment(HorizontalAlignment.CENTER); this.colNum = 0; this.currentRow = this.sheet.createRow(this.sheetRowNum++); this.currentCell = this.currentRow.createCell(this.colNum); this.currentCell.setCellStyle(style); String caption = model.getCaption(); this.currentCell.setCellValue(new HSSFRichTextString(caption)); this.rowSpanTable(model); }
HSSFRow row = sheet.createRow(srow); HSSFFont font = wb.createFont(); font.setBold(true); HSSFCellStyle cs = wb.createCellStyle(); cs.setAlignment(HorizontalAlignment.CENTER); HSSFFont font = wb.createFont(); font.setItalic(true); font.setBold(true); HSSFCellStyle cs = wb.createCellStyle(); cs.setAlignment(HorizontalAlignment.CENTER);
newFont.setStrikeout(cellFont.getStrikeout()); newFont.setTypeOffset(cellFont.getTypeOffset()); newFont.setBold(cellFont.getBold()); newFont.setCharSet(cellFont.getCharSet()); newFont.setColor(cellFont.getColor());
font.setBold(bold);