private HSSFCellStyle createHSSFCellStyle(Workbook wb, int[] bgColor, int[] fontColor, int fontSize) { HSSFWorkbook workbook = (HSSFWorkbook) wb; HSSFPalette palette = workbook.getCustomPalette(); palette.setColorAtIndex((short) 9, (byte) fontColor[0], (byte) fontColor[1], (byte) fontColor[2]); palette.setColorAtIndex((short) 10, (byte) bgColor[0], (byte) bgColor[1], (byte) bgColor[2]); HSSFFont titleFont = workbook.createFont(); titleFont.setCharSet(HSSFFont.DEFAULT_CHARSET); titleFont.setFontName("宋体"); titleFont.setColor((short) 9); titleFont.setBold(true); titleFont.setFontHeightInPoints((short) fontSize); HSSFCellStyle titleStyle = (HSSFCellStyle) createBorderCellStyle(workbook, true); titleStyle.setFont(titleFont); titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); titleStyle.setFillForegroundColor((short) 10); titleStyle.setAlignment(HorizontalAlignment.CENTER); titleStyle.setVerticalAlignment(VerticalAlignment.CENTER); return titleStyle; }
/** */ protected void createColumnHeaders() { final HSSFRow headersRow = this.sheet.createRow(0); final HSSFFont font = this.workbook.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); final HSSFCellStyle style = this.workbook.createCellStyle(); style.setFont(font); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); int counter = 1; for (int i = 0; i < this.model.getColumnCount(); i++) { final HSSFCell cell = headersRow.createCell(counter++); // cell.setEncoding(HSSFCell.ENCODING_UTF_16); cell.setCellValue(this.model.getColumnName(i)); cell.setCellStyle(style); } }
protected HSSFRichTextString getRichTextString(JRStyledText styledText, short forecolor, JRFont defaultFont, Locale locale) { String text = styledText.getText(); HSSFRichTextString richTextStr = new HSSFRichTextString(text); int runLimit = 0; AttributedCharacterIterator iterator = styledText.getAttributedString().getIterator(); while(runLimit < styledText.length() && (runLimit = iterator.getRunLimit()) <= styledText.length()) { Map<Attribute,Object> attributes = iterator.getAttributes(); JRFont runFont = attributes.isEmpty()? defaultFont : new JRBaseFont(attributes); short runForecolor = attributes.get(TextAttribute.FOREGROUND) != null ? getWorkbookColor((Color)attributes.get(TextAttribute.FOREGROUND)).getIndex() : forecolor; HSSFFont font = getLoadedFont(runFont, runForecolor, attributes, locale); richTextStr.applyFont(iterator.getIndex(), runLimit, font); iterator.setIndex(runLimit); } return richTextStr; }
protected HSSFCellStyle getLoadedCellStyle( FillPatternType mode, short backcolor, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, short rotation, HSSFFont font, BoxStyle box, boolean isWrapText, boolean isCellLocked, boolean isCellHidden, boolean isShrinkToFit ) { StyleInfo style = new StyleInfo(mode, backcolor, horizontalAlignment, verticalAlignment, rotation, font, box, isWrapText, isCellLocked, isCellHidden, isShrinkToFit); return getLoadedCellStyle(style); }
public StyleInfo( FillPatternType mode, short backcolor, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, short rotation, HSSFFont font, JRExporterGridCell gridCell, boolean wrapText, boolean cellLocked, boolean cellHidden, boolean shrinkToFit ) { this(mode, backcolor, horizontalAlignment, verticalAlignment, rotation, font, (gridCell == null ? null : new BoxStyle(gridCell)), wrapText, cellLocked, cellHidden, shrinkToFit); }
public static HSSFFont copyFont(final HSSFWorkbook workbook, final HSSFFont font) { final HSSFFont newFont = workbook.createFont(); // newFont.setBoldweight(font.getBoldweight()); // newFont.setCharSet(font.getCharSet()); // newFont.setColor(font.getColor()); // newFont.setFontHeight(font.getFontHeight()); // newFont.setFontHeightInPoints(font.getFontHeightInPoints()); // newFont.setFontName(font.getFontName()); // newFont.setItalic(font.getItalic()); // newFont.setStrikeout(font.getStrikeout()); // newFont.setTypeOffset(font.getTypeOffset()); // newFont.setUnderline(font.getUnderline()); return newFont; }
/** * * @Title: getCellStyle * @Description: TODO(设置表头样式) * @param wb * @return */ private CellStyle getHeadCellStyle(Workbook wb) { CellStyle style = wb.createCellStyle(); Font font = wb.createFont(); font.setFontName("宋体"); font.setFontHeightInPoints((short) 12);// 设置字体大小 font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 加粗 style.setFillForegroundColor(HSSFColor.LIME.index);// 设置背景色 style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setAlignment(HSSFCellStyle.SOLID_FOREGROUND);// 让单元格居中 style.setAlignment(HSSFCellStyle.ALIGN_CENTER); style.setBorderTop(CellStyle.BORDER_THIN); style.setBorderLeft(CellStyle.BORDER_THIN); style.setBorderRight(CellStyle.BORDER_THIN); style.setBorderBottom(CellStyle.BORDER_THIN); // style.setWrapText(true);//设置自动换行 style.setFont(font); return style; }
private FontMetrics getFontMetrics(HSSFFont hf){ FontMetrics fm; Short pFont = new Short(hf.getIndex()); fm = (FontMetrics) fontMetrics.get(pFont); if (fm == null) { int style; if((hf.getBoldweight() == HSSFFont.BOLDWEIGHT_BOLD) || hf.getItalic()) { style = 0; if(hf.getBoldweight() == HSSFFont.BOLDWEIGHT_BOLD) style ^= Font.BOLD; if(hf.getItalic()) style ^= Font.ITALIC; } else { style = Font.PLAIN; } Font f = new java.awt.Font(hf.getFontName(), style, hf.getFontHeightInPoints()); if (graphics == null) { BufferedImage i = new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_GRAY); graphics = i.createGraphics(); } fm = graphics.getFontMetrics(f); fontMetrics.put(pFont, fm); } return fm; }
public void notifyCellValue(String val, HSSFFont font) { if (val == null || val.length() == 0) return; if (font == null) throw new IllegalArgumentException("font is null"); short width; { FontMetrics fm = getFontMetrics(font); int w = fm.stringWidth(val); width = (w > Short.MAX_VALUE) ? Short.MAX_VALUE : (short) w; // TODO - this gives an underestimate with large font-sizes. // TODO - What we *should* be considering is the 'display width'. // This means we'd have to take into account cell type & format. } if (width > currentWidth) { currentWidth = width; } }
public static HSSFCellStyle createCellStyleForColumnHeading(HSSFWorkbook workBook) { HSSFCellStyle cellStyle = workBook.createCellStyle(); HSSFFont fontObj = workBook.createFont(); cellStyle.setBorderBottom(BorderStyle.THIN); cellStyle.setBorderTop(BorderStyle.THIN); cellStyle.setBorderLeft(BorderStyle.THIN); cellStyle.setBorderRight(BorderStyle.THIN); cellStyle.setWrapText(true); cellStyle.setAlignment(HorizontalAlignment.CENTER); cellStyle.setFillBackgroundColor(Short.valueOf("22").shortValue()); cellStyle.setFillPattern(FillPatternType.BIG_SPOTS); cellStyle.setFillForegroundColor(Short.valueOf("22").shortValue()); cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); fontObj.setFontName("Calibri"); fontObj.setFontHeightInPoints(Short.valueOf("12").shortValue()); fontObj.setBold(true); fontObj.setColor(Short.valueOf("8").shortValue()); cellStyle.setFont(fontObj); return cellStyle; }
public static HSSFFont copyFont(HSSFWorkbook workbook, HSSFFont font) { HSSFFont newFont = workbook.createFont(); // newFont.setBoldweight(font.getBoldweight()); // newFont.setCharSet(font.getCharSet()); // newFont.setColor(font.getColor()); // newFont.setFontHeight(font.getFontHeight()); // newFont.setFontHeightInPoints(font.getFontHeightInPoints()); // newFont.setFontName(font.getFontName()); // newFont.setItalic(font.getItalic()); // newFont.setStrikeout(font.getStrikeout()); // newFont.setTypeOffset(font.getTypeOffset()); // newFont.setUnderline(font.getUnderline()); return newFont; }
private static org.apache.poi.ss.usermodel.Font createPoiFont(PoiWorkbook workbook, Font other) { org.apache.poi.ss.usermodel.Font poiFont = workbook.getPoiWorkbook().createFont(); poiFont.setFontHeightInPoints((short) Math.round(other.getSizeInPoints())); poiFont.setFontName(other.getFamily()); final org.apache.poi.ss.usermodel.Color poiTextColor = workbook.getPoiColor(other.getColor()); if (poiFont instanceof HSSFFont && poiTextColor instanceof HSSFColor) { poiFont.setColor(((HSSFColor) poiTextColor).getIndex()); } else if (poiFont instanceof XSSFFont && poiTextColor instanceof XSSFColor) { ((XSSFFont) poiFont).setColor((XSSFColor) poiTextColor); } else { // it should both either be XSSF _or_ HSSF implementations so this // line should never be reached. throw new IllegalStateException(); } poiFont.setBold(other.isBold()); poiFont.setItalic(other.isItalic()); poiFont.setStrikeout(other.isStrikeThrough()); poiFont.setUnderline(other.isUnderlined() ? org.apache.poi.ss.usermodel.Font.U_SINGLE : org.apache.poi.ss.usermodel.Font.U_NONE); return poiFont; }
private HSSFCellStyle getHeaderStyle(final int col) { String key = "header-" + col; HSSFCellStyle cs_header = m_styles.get(key); if (cs_header == null) { HSSFFont font_header = getFont(true); cs_header = m_workbook.createCellStyle(); cs_header.setFont(font_header); cs_header.setBorderLeft((short)2); cs_header.setBorderTop((short)2); cs_header.setBorderRight((short)2); cs_header.setBorderBottom((short)2); cs_header.setDataFormat(HSSFDataFormat.getBuiltinFormat("text")); cs_header.setWrapText(true); m_styles.put(key, cs_header); } return cs_header; }
private HSSFCellStyle createSecondTitleStyle(HSSFWorkbook wb){ HSSFCellStyle style = wb.createCellStyle(); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); style.setAlignment(HSSFCellStyle.ALIGN_LEFT); style.setBorderBottom(HSSFCellStyle.BORDER_NONE); style.setBorderLeft(HSSFCellStyle.BORDER_NONE); style.setBorderRight(HSSFCellStyle.BORDER_NONE); style.setBorderTop(HSSFCellStyle.BORDER_NONE); style.setWrapText(true); HSSFFont font = wb.createFont(); //font.setFontHeightInPoints((short)20); font.setFontName("����"); style.setFont(font); return style; }
/** * @Description: 生成excel表格 单元格内容的样式 * @param workbook * @return * * @History * 1. 2014-12-19 linwb 创建方法 */ private HSSFCellStyle generateContStyle(HSSFWorkbook workbook) { HSSFCellStyle cellStyle = workbook.createCellStyle(); cellStyle.setFillForegroundColor(contCellBackgroundColor); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); cellStyle.setBorderBottom(contBorderBottom); cellStyle.setBorderLeft(contBorderLeft); cellStyle.setBorderRight(contBorderRight); cellStyle.setBorderTop(contBorderTop); cellStyle.setAlignment(contCellTextAlign); cellStyle.setVerticalAlignment(contCellVehicleAlign); // 生成字体 HSSFFont font = workbook.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); // 把字体应用到当前的样式 cellStyle.setFont(font); return cellStyle; }
/** * Estilo de cabecalho. * @param wb * @return retorna o estilo da celula. * @author Ekler Paulino de Mattos. */ private HSSFCellStyle estiloCabecalho(HSSFWorkbook wb){ HSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THICK); cellStyle.setBorderRight(HSSFCellStyle.BORDER_THICK); cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THICK); cellStyle.setBorderTop(HSSFCellStyle.BORDER_THICK); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND ); // cellStyle.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index); cellStyle.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index); cellStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT); HSSFFont font = cellStyle.getFont(wb); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); font.setColor(HSSFFont.COLOR_NORMAL); font.setFontName(HSSFFont.FONT_ARIAL); cellStyle.setFont(font); return cellStyle; }
/** * Estilo dos campos dos dados. * @param wb * @return retorna o estilo da celula. * @author Ekler Paulino de Mattos. */ private HSSFCellStyle estiloDadosConsultado(HSSFWorkbook wb){ HSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM); cellStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM); cellStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM); cellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM); // plano de fundo - para que funcione deve se // definido antes um padrao de preenchimento. cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND ); //cellStyle.setFillForegroundColor(HSSFColor.AQUA.index); cellStyle.setFillForegroundColor(HSSFColor.WHITE.index); cellStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT); HSSFFont font = cellStyle.getFont(wb); font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); font.setColor(HSSFFont.COLOR_NORMAL); font.setFontName(HSSFFont.FONT_ARIAL); cellStyle.setFont(font); return cellStyle; }
/** * Estilo dos campos dos dados. * @param wb * @return retorna o estilo da celula. * @author Ekler Paulino de Mattos. */ private HSSFCellStyle estiloDadosRetorno(HSSFWorkbook wb){ HSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM); cellStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM); cellStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM); cellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM); // plano de fundo - para que funcione deve se // definido antes um padrao de preenchimento. cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND ); //cellStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); cellStyle.setFillForegroundColor(HSSFColor.PALE_BLUE.index); cellStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT); HSSFFont font = cellStyle.getFont(wb); font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); font.setColor(HSSFFont.COLOR_NORMAL); font.setFontName(HSSFFont.FONT_ARIAL); cellStyle.setFont(font); return cellStyle; }
/** * Estilo de cabecalho. * @param wb * @return retorna o estilo da celula. * @author Ekler Paulino de Mattos. */ private HSSFCellStyle estiloCabecalho(HSSFWorkbook wb){ if(this.estiloCabecalho==null){ this.estiloCabecalho = wb.createCellStyle(); this.estiloCabecalho.setBorderBottom(HSSFCellStyle.BORDER_THIN); this.estiloCabecalho.setBorderRight(HSSFCellStyle.BORDER_THIN); this.estiloCabecalho.setBorderLeft(HSSFCellStyle.BORDER_THIN); this.estiloCabecalho.setBorderTop(HSSFCellStyle.BORDER_THIN); this.estiloCabecalho.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND ); // cellStyle.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index); this.estiloCabecalho.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index); this.estiloCabecalho.setAlignment(HSSFCellStyle.ALIGN_LEFT); HSSFFont font = this.estiloCabecalho.getFont(wb); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); font.setColor(HSSFFont.COLOR_NORMAL); font.setFontName(HSSFFont.FONT_ARIAL); this.estiloCabecalho.setFont(font); } return this.estiloCabecalho; }
/** * HSSFフォントの文字列表現を取得する * * @param workbook ブック * @param font フォント * @return フォントの文字列表現 */ private static String getHSSFFontString( HSSFWorkbook workbook, HSSFFont font) { StringBuffer sb = new StringBuffer(); sb.append( "[FONT]"); sb.append( "fontheight=").append( Integer.toHexString( font.getFontHeight())).append( ","); sb.append( "italic=").append( font.getItalic()).append( ","); sb.append( "strikout=").append( font.getStrikeout()).append( ","); sb.append( "colorpalette=").append( getHSSFColorString( ( HSSFWorkbook) workbook, font.getColor())).append( ","); sb.append( "boldweight=").append( Integer.toHexString( font.getBoldweight())).append( ","); sb.append( "supersubscript=").append( Integer.toHexString( font.getTypeOffset())).append( ","); sb.append( "underline=").append( Integer.toHexString( font.getUnderline())).append( ","); sb.append( "charset=").append( Integer.toHexString( font.getCharSet())).append( ","); sb.append( "fontname=").append( font.getFontName()); sb.append( "[/FONT]"); return sb.toString(); }
/** * @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.setBoldweight(Font.BOLDWEIGHT_BOLD); bold.setFontHeightInPoints((short) 14); style.setFont(bold); style.setAlignment(CellStyle.ALIGN_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); }
/** * HSSFフォントの文字列表現を取得する * * @param workbook ブック * @param font フォント * @return フォントの文字列表現 */ private static String getHSSFFontString( HSSFWorkbook workbook, HSSFFont font) { StringBuffer sb = new StringBuffer(); sb.append( "[FONT]"); sb.append( "fontheight=").append( Integer.toHexString( font.getFontHeight())).append( ","); sb.append( "italic=").append( font.getItalic()).append( ","); sb.append( "strikout=").append( font.getStrikeout()).append( ","); sb.append( "colorpalette=").append( getHSSFColorString( ( HSSFWorkbook) workbook, font.getColor())).append( ","); sb.append( "bold=").append( font.getBold()).append( ","); sb.append( "supersubscript=").append( Integer.toHexString( font.getTypeOffset())).append( ","); sb.append( "underline=").append( Integer.toHexString( font.getUnderline())).append( ","); sb.append( "charset=").append( Integer.toHexString( font.getCharSet())).append( ","); sb.append( "fontname=").append( font.getFontName()); sb.append( "[/FONT]"); return sb.toString(); }
private CellStyle createHeaderStyle(){ //TO-DO read style information from sakai.properties Font font = gradesWorkbook.createFont(); font.setFontName(HSSFFont.FONT_ARIAL); font.setColor(IndexedColors.PLUM.getIndex()); font.setBold(true); CellStyle cellStyle = gradesWorkbook.createCellStyle(); cellStyle.setFont(font); return cellStyle; }
@Override public void addColourToFont(Workbook workbook, Font font, String colour) { if(colour == null) { return ; } if(IStyle.TRANSPARENT_VALUE.equals(colour)) { return ; } if(font instanceof HSSFFont) { HSSFFont hFont = (HSSFFont)font; short colourIndex = getHColour((HSSFWorkbook)workbook, colour); if( colourIndex > 0 ) { hFont.setColor(colourIndex); } } }
/** * ereditare questo metodo per modificare gli stili utilizzati */ protected void initStili() { HSSFFont fontGrassetto = _workBook.createFont(); fontGrassetto.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); fontGrassetto.setFontHeightInPoints((short) 10); HSSFFont fontTesto = _workBook.createFont(); fontTesto.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL ); fontTesto.setFontHeightInPoints((short) 10); _styleIntestazioni = _workBook.createCellStyle(); _styleIntestazioni.setFont(fontGrassetto); _styleIntestazioni.setBorderTop(HSSFCellStyle.BORDER_MEDIUM); _styleIntestazioni.setBorderRight(HSSFCellStyle.BORDER_MEDIUM); _styleIntestazioni.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM); _styleIntestazioni.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM); _styleIntestazioni.setAlignment(HSSFCellStyle.ALIGN_CENTER); _styleIntestazioni.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); _styleTesto = _workBook.createCellStyle(); _styleTesto.setFont(fontTesto); }
/** * Gets the string representation of the given <code>Font</code>. * @param f A <code>Font</code>. * @return The string representation. */ private String getRepresentation(Font f) { // Colors that need an instanceof check Color fontColor; if (f instanceof HSSFFont) { HSSFFont hf = (HSSFFont) f; fontColor = hf.getHSSFColor((HSSFWorkbook) myWorkbook); } else if (f instanceof XSSFFont) { XSSFFont xf = (XSSFFont) f; fontColor = xf.getXSSFColor(); } else throw new IllegalArgumentException("Bad Font type: " + f.getClass().getName()); return getRepresentation(f.getBoldweight(), f.getItalic(), fontColor, f.getFontName(), f.getFontHeightInPoints(), f.getUnderline(), f.getStrikeout(), f.getCharSet(), f.getTypeOffset()); }
@Override public boolean equals(Object obj) { if (obj instanceof HSSFFontCacheKey) { HSSFFontCacheKey objKey = (HSSFFontCacheKey) obj; HSSFFont objFont = objKey.font; if (font == objFont) { return true; } if (objFont == null) { return false; } if (fontRecord == null) { if (objKey.fontRecord != null) { return false; } } else if (!fontRecord.equals(objKey.fontRecord)) { return false; } return true; } else { return false; } }
private void setHeaderStyle(HSSFWorkbook wb) { HSSFCellStyle style = wb.createCellStyle(); HSSFFont font = wb.createFont(); font.setColor(HSSFColor.BLACK.index); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); font.setFontHeightInPoints((short) 8); style.setFont(font); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); style.setBorderRight(HSSFCellStyle.BORDER_THIN); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBorderTop(HSSFCellStyle.BORDER_THIN); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); style.setWrapText(true); headerStyle = style; }
private void setVerticalHeaderStyle(HSSFWorkbook wb) { verticalHeaderStyle = wb.createCellStyle(); HSSFFont font = wb.createFont(); font.setColor(HSSFColor.BLACK.index); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); font.setFontHeightInPoints((short) 8); verticalHeaderStyle.setFont(font); verticalHeaderStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); verticalHeaderStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); verticalHeaderStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); verticalHeaderStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); verticalHeaderStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); verticalHeaderStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); verticalHeaderStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); verticalHeaderStyle.setRotation((short) 90); }
private void fontStyle(CellStyle style) { Font font = wb.getFontAt(style.getFontIndex()); if (font.getBoldweight() >= HSSFFont.BOLDWEIGHT_NORMAL) out.format(" font-weight: bold;%n"); if (font.getItalic()) out.format(" font-style: italic;%n"); int fontheight = font.getFontHeightInPoints(); if (fontheight == 9) { //fix for stupid ol Windows fontheight = 10; } out.format(" font-size: %dpt;%n", fontheight); // Font color is handled with the other colors }
@Override protected void buildExcelDocument(Map<String, Object> model, HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception { // get data model which is passed by the Spring container List<RatingCountBean> listOfRating = (List<RatingCountBean>) model.get("listOfRatingCount"); // create a new Excel sheet HSSFSheet sheet = workbook.createSheet("Feedback Report"); sheet.setDefaultColumnWidth(30); // create style for header cells CellStyle style = workbook.createCellStyle(); Font font = workbook.createFont(); font.setFontName("Arial"); style.setFillForegroundColor(HSSFColor.BLUE.index); style.setFillPattern(CellStyle.SOLID_FOREGROUND); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); font.setColor(HSSFColor.WHITE.index); style.setFont(font); // create header row HSSFRow header = sheet.createRow(0); header.createCell(0).setCellValue("Question Number"); header.getCell(0).setCellStyle(style); header.createCell(1).setCellValue("Question"); header.getCell(1).setCellStyle(style); header.createCell(2).setCellValue("Very Poor"); header.getCell(2).setCellStyle(style); header.createCell(3).setCellValue("Poor"); header.getCell(3).setCellStyle(style); header.createCell(4).setCellValue("Good"); header.getCell(4).setCellStyle(style); header.createCell(5).setCellValue("Best"); header.getCell(5).setCellStyle(style); header.createCell(6).setCellValue("Excellent"); header.getCell(6).setCellStyle(style); // create data rows int rowCount = 1; for (RatingCountBean rating : listOfRating) { HSSFRow aRow = sheet.createRow(rowCount++); aRow.createCell(0).setCellValue(rating.getQuestionId()); aRow.createCell(1).setCellValue(rating.getQuestionText()); aRow.createCell(2).setCellValue(rating.getRating_one_total_count()); aRow.createCell(3).setCellValue(rating.getRating_two_total_count()); aRow.createCell(4).setCellValue(rating.getRating_three_total_count()); aRow.createCell(5).setCellValue(rating.getRating_four_total_count()); aRow.createCell(6).setCellValue(rating.getRating_five_total_count()); } }
private XSSFCellStyle createXSSFCellStyle(Workbook wb, int[] bgColor, int[] fontColor, int fontSize) { SXSSFWorkbook workbook = (SXSSFWorkbook) wb; XSSFFont titleFont = (XSSFFont) workbook.createFont(); titleFont.setCharSet(HSSFFont.DEFAULT_CHARSET); titleFont.setFontName("宋体"); XSSFColor color9 = new XSSFColor(new java.awt.Color(fontColor[0], fontColor[1], fontColor[2])); XSSFColor color10 = new XSSFColor(new java.awt.Color(bgColor[0], bgColor[1], bgColor[2])); if (!(fontColor[0] == 0 && fontColor[1] == 0 && fontColor[2] == 0)) { titleFont.setColor(color9); } titleFont.setBold(true); titleFont.setFontHeightInPoints((short) fontSize); XSSFCellStyle titleStyle = (XSSFCellStyle) createBorderCellStyle(workbook, true); titleStyle.setFont(titleFont); titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); titleStyle.setFillForegroundColor(color10); titleStyle.setAlignment(HorizontalAlignment.CENTER); titleStyle.setVerticalAlignment(VerticalAlignment.CENTER); return titleStyle; }
private void createHeader( HSSFWorkbook wb, HSSFSheet sheet, List<TascaDadaDto> informeCamps) { HSSFFont bold; bold = wb.createFont(); bold.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); bold.setColor(HSSFColor.WHITE.index); HSSFCellStyle headerStyle; headerStyle = wb.createCellStyle(); headerStyle.setFillPattern(HSSFCellStyle.FINE_DOTS); headerStyle.setFillBackgroundColor(HSSFColor.GREY_80_PERCENT.index); headerStyle.setFont(bold); int rowNum = 0; int colNum = 0; // Capçalera HSSFRow xlsRow = sheet.createRow(rowNum++); HSSFCell cell; cell = xlsRow.createCell(colNum++); cell.setCellValue(new HSSFRichTextString(StringUtils.capitalize("Expedient"))); cell.setCellStyle(headerStyle); for (TascaDadaDto camp : informeCamps) { sheet.autoSizeColumn(colNum); cell = xlsRow.createCell(colNum++); cell.setCellValue(new HSSFRichTextString(StringUtils.capitalize(camp.getCampEtiqueta()))); cell.setCellStyle(headerStyle); } }
@Override protected void buildExcelDocument(Map<String, Object> model, HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception { // get data model which is passed by the Spring container @SuppressWarnings("unchecked") List<HrmsLogin> users = (List<HrmsLogin>) model.get("allUsers"); // create a new Excel sheet HSSFSheet sheet = workbook.createSheet("User List"); sheet.setDefaultColumnWidth(30); // create style for header cells CellStyle style = workbook.createCellStyle(); Font font = workbook.createFont(); font.setFontName("Arial"); style.setFillForegroundColor(HSSFColor.BLUE.index); style.setFillPattern(CellStyle.SOLID_FOREGROUND); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); font.setColor(HSSFColor.WHITE.index); style.setFont(font); // create header row HSSFRow header = sheet.createRow(0); header.createCell(0).setCellValue("Employee ID"); header.getCell(0).setCellStyle(style); header.createCell(1).setCellValue("Username"); header.getCell(1).setCellStyle(style); header.createCell(2).setCellValue("Password"); header.getCell(2).setCellStyle(style); header.createCell(3).setCellValue("Role"); header.getCell(3).setCellStyle(style); // create data rows int rowCount = 1; for (HrmsLogin account : users) { HSSFRow aRow = sheet.createRow(rowCount++); aRow.createCell(0).setCellValue(account.getHrmsEmployeeDetails().getEmpId()); aRow.createCell(1).setCellValue(account.getUsername()); aRow.createCell(2).setCellValue(account.getPassword()); aRow.createCell(3).setCellValue(account.getRole()); } }
private static void setBold(HSSFWorkbook workbook, HSSFCell cell) { HSSFCellStyle boldStyle = workbook.createCellStyle(); HSSFFont boldFont = workbook.createFont(); boldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); boldStyle.setFont(boldFont); cell.setCellStyle(boldStyle); }
private void setHeaderStyle() { headerStyle = wb.createCellStyle(); font.setFontHeightInPoints((short) 11); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); font.setColor(HSSFColor.WHITE.index); headerStyle.setFont(font); headerStyle.setFillForegroundColor(HSSFColor.LIGHT_BLUE.index); headerStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); }
private void setTitleStyle() { titleStyle = wb.createCellStyle(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); font.setColor(HSSFColor.WHITE.index); font.setFontHeightInPoints((short) 14); titleStyle.setFont(font); titleStyle.setFillForegroundColor(HSSFColor.LIGHT_BLUE.index); titleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); }