List of usage examples for org.apache.poi.hssf.usermodel HSSFFont BOLDWEIGHT_NORMAL
short BOLDWEIGHT_NORMAL
To view the source code for org.apache.poi.hssf.usermodel HSSFFont BOLDWEIGHT_NORMAL.
Click Source Link
From source file:com.bdx.rainbow.spsy.service.impl.EnterpriseLicenseServiceImpl.java
/** * * @param title ??// ww w . j a v a 2 s . c om * @param headers ?? * @param resultLists ? * @param pattern ?,"yyyy-MM-dd" */ private HSSFWorkbook exportExcel(String title, String[] headers, List<DubboEnterpriseLicense> resultLists, String pattern) { if (resultLists == null) { return null; } if (pattern == null && StringUtils.isEmpty(pattern)) { pattern = "yyyy-MM-dd"; } SimpleDateFormat sdf = new SimpleDateFormat(pattern); // HSSFWorkbook workbook = new HSSFWorkbook(); // ? HSSFSheet sheet = workbook.createSheet(title); // 15 sheet.setDefaultColumnWidth((short) 15); // ?? HSSFCellStyle style = workbook.createCellStyle(); // ? style.setFillForegroundColor(HSSFColor.SKY_BLUE.index); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); style.setBorderRight(HSSFCellStyle.BORDER_THIN); style.setBorderTop(HSSFCellStyle.BORDER_THIN); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // ? HSSFFont font = workbook.createFont(); font.setColor(HSSFColor.VIOLET.index); font.setFontHeightInPoints((short) 12); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // ?? style.setFont(font); // ??? HSSFCellStyle style2 = workbook.createCellStyle(); style2.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index); style2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style2.setBorderBottom(HSSFCellStyle.BORDER_THIN); style2.setBorderLeft(HSSFCellStyle.BORDER_THIN); style2.setBorderRight(HSSFCellStyle.BORDER_THIN); style2.setBorderTop(HSSFCellStyle.BORDER_THIN); style2.setAlignment(HSSFCellStyle.ALIGN_CENTER); style2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // ?? HSSFFont font2 = workbook.createFont(); font2.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); // ?? style2.setFont(font2); // HSSFRow row = sheet.createRow(0); for (short i = 0; i < headers.length; i++) { HSSFCell cell = row.createCell(i); cell.setCellStyle(style); HSSFRichTextString text = new HSSFRichTextString(headers[i]); cell.setCellValue(text); } // ????? for (int i = 0; i < resultLists.size(); i++) { row = sheet.createRow(i + 1); int index = 0; // HSSFCell cell = row.createCell(j); // row.createCell(index++).setCellStyle(style2); DubboEnterpriseLicense info = resultLists.get(i); row.createCell(index++).setCellValue(info.getEnterpriseName()); row.createCell(index++).setCellValue(info.getOrganizationCode()); row.createCell(index++).setCellValue(info.getLegalPerson()); row.createCell(index++).setCellValue(info.getLegalPersonPhone()); String type = info.getLicenseType(); if ("001".equals(type)) { row.createCell(index++).setCellValue(""); } else if ("002".equals(type)) { row.createCell(index++).setCellValue("??"); } else if ("003".equals(type)) { row.createCell(index++).setCellValue(""); } else if ("004".equals(type)) { row.createCell(index++).setCellValue("?"); } else { row.createCell(index++).setCellValue(type); } row.createCell(index++).setCellValue(info.getLicenseCode()); if (info.getLicenseTime() != null) { row.createCell(index++).setCellValue(sdf.format(info.getLicenseTime())); } else { row.createCell(index++).setCellValue(""); } if (info.getInvalidDate() != null) { Long time = (System.currentTimeMillis() - info.getInvalidDate().getTime()) / (1000 * 3600 * 24); if (time > 0) { row.createCell(index++).setCellValue(""); } else if (time <= 0) { row.createCell(index++).setCellValue(""); } else { row.createCell(index++).setCellValue("1"); } } else { row.createCell(index++).setCellValue(""); } } return workbook; }
From source file:com.common.report.util.html.ToHtml.java
License:Apache License
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;// w ww.jav a2 s.co m } out.format(" font-size: %dpt;%n", fontheight); // Font color is handled with the other colors }
From source file:com.demo.common.extreme.view.XlsView.java
License:Apache License
private Map initStyles(HSSFWorkbook wb, short fontHeight) { Map result = new HashMap(); HSSFCellStyle titleStyle = wb.createCellStyle(); HSSFCellStyle textStyle = wb.createCellStyle(); HSSFCellStyle boldStyle = wb.createCellStyle(); HSSFCellStyle numericStyle = wb.createCellStyle(); HSSFCellStyle numericStyleBold = wb.createCellStyle(); HSSFCellStyle moneyStyle = wb.createCellStyle(); HSSFCellStyle moneyStyleBold = wb.createCellStyle(); HSSFCellStyle percentStyle = wb.createCellStyle(); HSSFCellStyle percentStyleBold = wb.createCellStyle(); // Add to export totals HSSFCellStyle moneyStyle_Totals = wb.createCellStyle(); HSSFCellStyle naStyle_Totals = wb.createCellStyle(); HSSFCellStyle numericStyle_Totals = wb.createCellStyle(); HSSFCellStyle percentStyle_Totals = wb.createCellStyle(); HSSFCellStyle textStyle_Totals = wb.createCellStyle(); result.put("titleStyle", titleStyle); result.put("textStyle", textStyle); result.put("boldStyle", boldStyle); result.put("numericStyle", numericStyle); result.put("numericStyleBold", numericStyleBold); result.put("moneyStyle", moneyStyle); result.put("moneyStyleBold", moneyStyleBold); result.put("percentStyle", percentStyle); result.put("percentStyleBold", percentStyleBold); // Add to export totals result.put("moneyStyle_Totals", moneyStyle_Totals); result.put("naStyle_Totals", naStyle_Totals); result.put("numericStyle_Totals", numericStyle_Totals); result.put("percentStyle_Totals", percentStyle_Totals); result.put("textStyle_Totals", textStyle_Totals); HSSFDataFormat format = wb.createDataFormat(); // Global fonts HSSFFont font = wb.createFont();//from www. j a va2s . c o m font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); font.setColor(HSSFColor.BLACK.index); font.setFontName(HSSFFont.FONT_ARIAL); font.setFontHeightInPoints(fontHeight); HSSFFont fontBold = wb.createFont(); fontBold.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); fontBold.setColor(HSSFColor.BLACK.index); fontBold.setFontName(HSSFFont.FONT_ARIAL); fontBold.setFontHeightInPoints(fontHeight); // Money Style moneyStyle.setFont(font); moneyStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT); moneyStyle.setDataFormat(format.getFormat(moneyFormat)); // Money Style Bold moneyStyleBold.setFont(fontBold); moneyStyleBold.setAlignment(HSSFCellStyle.ALIGN_RIGHT); moneyStyleBold.setDataFormat(format.getFormat(moneyFormat)); // Percent Style percentStyle.setFont(font); percentStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT); percentStyle.setDataFormat(format.getFormat(percentFormat)); // Percent Style Bold percentStyleBold.setFont(fontBold); percentStyleBold.setAlignment(HSSFCellStyle.ALIGN_RIGHT); percentStyleBold.setDataFormat(format.getFormat(percentFormat)); // Standard Numeric Style numericStyle.setFont(font); numericStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT); // Standard Numeric Style Bold numericStyleBold.setFont(fontBold); numericStyleBold.setAlignment(HSSFCellStyle.ALIGN_RIGHT); // Title Style titleStyle.setFont(font); titleStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); titleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); titleStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); titleStyle.setBottomBorderColor(HSSFColor.BLACK.index); titleStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); titleStyle.setLeftBorderColor(HSSFColor.BLACK.index); titleStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); titleStyle.setRightBorderColor(HSSFColor.BLACK.index); titleStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); titleStyle.setTopBorderColor(HSSFColor.BLACK.index); titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); titleStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // Standard Text Style textStyle.setFont(font); textStyle.setWrapText(true); // Standard Text Style boldStyle.setFont(fontBold); boldStyle.setWrapText(true); // Money Style Total moneyStyle_Totals.setFont(fontBold); moneyStyle_Totals.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); moneyStyle_Totals.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); moneyStyle_Totals.setBorderBottom(HSSFCellStyle.BORDER_THIN); moneyStyle_Totals.setBottomBorderColor(HSSFColor.BLACK.index); moneyStyle_Totals.setBorderTop(HSSFCellStyle.BORDER_THIN); moneyStyle_Totals.setTopBorderColor(HSSFColor.BLACK.index); moneyStyle_Totals.setAlignment(HSSFCellStyle.ALIGN_RIGHT); moneyStyle_Totals.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); moneyStyle_Totals.setDataFormat(format.getFormat(moneyFormat)); // n/a Style Total naStyle_Totals.setFont(fontBold); naStyle_Totals.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); naStyle_Totals.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); naStyle_Totals.setBorderBottom(HSSFCellStyle.BORDER_THIN); naStyle_Totals.setBottomBorderColor(HSSFColor.BLACK.index); naStyle_Totals.setBorderTop(HSSFCellStyle.BORDER_THIN); naStyle_Totals.setTopBorderColor(HSSFColor.BLACK.index); naStyle_Totals.setAlignment(HSSFCellStyle.ALIGN_RIGHT); naStyle_Totals.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // Numeric Style Total numericStyle_Totals.setFont(fontBold); numericStyle_Totals.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); numericStyle_Totals.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); numericStyle_Totals.setBorderBottom(HSSFCellStyle.BORDER_THIN); numericStyle_Totals.setBottomBorderColor(HSSFColor.BLACK.index); numericStyle_Totals.setBorderTop(HSSFCellStyle.BORDER_THIN); numericStyle_Totals.setTopBorderColor(HSSFColor.BLACK.index); numericStyle_Totals.setAlignment(HSSFCellStyle.ALIGN_RIGHT); numericStyle_Totals.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // Percent Style Total percentStyle_Totals.setFont(fontBold); percentStyle_Totals.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); percentStyle_Totals.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); percentStyle_Totals.setBorderBottom(HSSFCellStyle.BORDER_THIN); percentStyle_Totals.setBottomBorderColor(HSSFColor.BLACK.index); percentStyle_Totals.setBorderTop(HSSFCellStyle.BORDER_THIN); percentStyle_Totals.setTopBorderColor(HSSFColor.BLACK.index); percentStyle_Totals.setAlignment(HSSFCellStyle.ALIGN_RIGHT); percentStyle_Totals.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); percentStyle_Totals.setDataFormat(format.getFormat(percentFormat)); // Text Style Total textStyle_Totals.setFont(fontBold); textStyle_Totals.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); textStyle_Totals.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); textStyle_Totals.setBorderBottom(HSSFCellStyle.BORDER_THIN); textStyle_Totals.setBottomBorderColor(HSSFColor.BLACK.index); textStyle_Totals.setBorderTop(HSSFCellStyle.BORDER_THIN); textStyle_Totals.setTopBorderColor(HSSFColor.BLACK.index); textStyle_Totals.setAlignment(HSSFCellStyle.ALIGN_LEFT); textStyle_Totals.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); return result; }
From source file:com.googlecode.testcase.annotation.handle.toexcel.strategy.ToHtmlWithExcel.java
License:Apache License
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;//from www .jav a 2s . c o m } out.format(" font-size: %dpt;%n", fontheight); // Font color is handled with the other colors }
From source file:com.hurry.excel.html.Excel2Html.java
License:Apache License
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;/*w w w. j a va 2 s . c o m*/ } out.format(" font-size: %dpt;%n", fontheight); // Font color is handled with the other colors }
From source file:com.leosys.core.utils.ExcelUtil.java
public void exportExcel(List<?> dataList, OutputStream out) throws Exception { HSSFWorkbook workbook = null;//from w w w .java 2s . c om HSSFSheet sheet = null; HSSFRow row = null; HSSFCell cell = null; HSSFCellStyle titleStyle = null; int rowIndex = 0; try { workbook = new HSSFWorkbook();// sheet = workbook.createSheet("?");// ? sheet.setDefaultColumnWidth((short) 30);// 15 titleStyle = workbook.createCellStyle();//? titleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); titleStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); titleStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); titleStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); titleStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); titleStyle.setFillForegroundColor(HSSFColor.WHITE.index); titleStyle.setFillBackgroundColor(HSSFColor.WHITE.index); titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); titleStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); HSSFFont font = workbook.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); font.setFontHeightInPoints((short) 17); titleStyle.setFont(font); row = sheet.createRow(rowIndex++); row.setHeight((short) 600); for (short i = 0; i < headArr.length; i++) { cell = row.createCell(i); //? if (i == 0) cell.setCellValue(new HSSFRichTextString(title)); cell.setCellStyle(titleStyle); } // ??? sheet.addMergedRegion(new Region(0, (short) 0, 0, (short) (headArr.length - 1))); titleStyle = workbook.createCellStyle(); titleStyle.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index); titleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); titleStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); titleStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); titleStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); titleStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); titleStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); font = workbook.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); font.setFontHeightInPoints((short) 13); titleStyle.setFont(font);// ?? row = sheet.createRow(rowIndex++);// for (short i = 0; i < headArr.length; i++) { cell = row.createCell(i); cell.setCellStyle(titleStyle); cell.setCellValue(new HSSFRichTextString(headArr[i])); } //? titleStyle = workbook.createCellStyle(); titleStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); titleStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); titleStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); titleStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); if (dataList == null || dataList.isEmpty()) return; short dataType = 0;// if (dataList.get(0) instanceof Map<?, ?>) dataType = 1; else if (dataList.get(0) instanceof List<?>) dataType = 2; if (dataType == 0) { String[] dataArr = null; for (Object data : dataList) { dataArr = (String[]) data; if (dataArr == null) continue; row = sheet.createRow(rowIndex++); for (short i = 0; i < headArr.length; i++) { if (i < dataArr.length) { Object val = dataArr[i]; if (rendererArr != null && rendererArr[i] != null) val = rendererArr[i].renderer(dataArr[i], i, dataArr); fillCell(row, titleStyle, font, i, val); } } } } else if (dataType == 1) { Map<?, ?> map = null; for (Object data : dataList) { map = (Map<?, ?>) data; if (map == null) continue; Object[] dataArr = map.values().toArray(); if (dataArr == null) continue; row = sheet.createRow(rowIndex++); for (short i = 0; i < headArr.length; i++) { if (i < dataArr.length) { Object val = dataArr[i]; if (rendererArr != null && rendererArr[i] != null) val = rendererArr[i].renderer(dataArr[i], i, dataArr); fillCell(row, titleStyle, font, i, val); } } } } else if (dataType == 2) { List<?> list = null; for (Object data : dataList) { list = (List<?>) data; if (list == null || list.isEmpty()) continue; row = sheet.createRow(rowIndex++); for (short i = 0; i < headArr.length; i++) { if (i < list.size()) { Object val = list.get(i); if (rendererArr != null && rendererArr[i] != null) val = rendererArr[i].renderer(list.get(i), i, list); fillCell(row, titleStyle, font, i, val); } } } } else throw new Exception("excel???"); workbook.write(out); } catch (Exception e) { throw new Exception("excel" + e.getMessage()); } finally { // if(out != null){ // try { // out.close(); // } catch (IOException e) {} // } } }
From source file:com.nokia.s60tools.swmtanalyser.model.ExcelCreator.java
License:Open Source License
/** * create set of cell styles/*www. j a v a 2 s.co m*/ */ private Map<String, HSSFCellStyle> createStyles(HSSFWorkbook wb) { Map<String, HSSFCellStyle> styles = new HashMap<String, HSSFCellStyle>(); HSSFCellStyle style; HSSFFont headerFont = wb.createFont(); headerFont.setColor(HSSFColor.WHITE.index); headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); headerFont.setFontHeightInPoints((short) 18); style = createBorderedStyle(wb); style.setAlignment(HSSFCellStyle.ALIGN_LEFT); style.setFillForegroundColor(HSSFColor.BLUE.index); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setFont(headerFont); styles.put("header", style); HSSFFont font1 = wb.createFont(); font1.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); font1.setFontHeightInPoints((short) 12); font1.setFontName(HSSFFont.FONT_ARIAL); font1.setColor(HSSFColor.WHITE.index); style = createBorderedStyle(wb); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); style.setFillForegroundColor(HSSFColor.BLUE.index); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setFont(font1); style.setWrapText(true); styles.put("header2", style); style = createBorderedStyle(wb); style.setAlignment(HSSFCellStyle.ALIGN_LEFT); style.setFillForegroundColor(HSSFColor.BLUE.index); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setFont(font1); style.setWrapText(true); styles.put("header1", style); HSSFFont font3 = wb.createFont(); font3.setColor(HSSFColor.BLACK.index); font3.setFontHeightInPoints((short) 10); font3.setFontName(HSSFFont.FONT_ARIAL); font3.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); style = createBorderedStyle(wb); style.setAlignment(HSSFCellStyle.ALIGN_LEFT); style.setFont(font3); styles.put("cell_bold", style); HSSFFont font5 = wb.createFont(); font5.setColor(HSSFColor.BLACK.index); font5.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); style = createBorderedStyle(wb); style.setAlignment(HSSFCellStyle.ALIGN_LEFT); style.setFont(font5); styles.put("cell_normal", style); HSSFFont font4 = wb.createFont(); font4.setFontHeightInPoints((short) 10); font4.setColor(HSSFColor.WHITE.index); style = createBorderedStyle(wb); style.setFillForegroundColor(HSSFColor.BLUE.index); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setFont(font4); styles.put("cell_blue_font_white", style); style = createBorderedStyle(wb); style.setAlignment(HSSFCellStyle.ALIGN_RIGHT); styles.put("cell_number", style); HSSFFont blue_font = wb.createFont(); blue_font.setFontHeightInPoints((short) 10); blue_font.setColor(HSSFColor.BLUE.index); style = createBorderedStyle(wb); style.setAlignment(HSSFCellStyle.ALIGN_RIGHT); style.setFont(blue_font); styles.put("blue_font", style); return styles; }
From source file:com.plugin.excel.util.ExcelFileHelper.java
License:Apache License
private static void formatCell(Workbook workbook, Cell cell, ExcelCell excell, Map<IndexedColors, CellStyle> s_cellStyle, Font font, Font invisibleFont) { if (excell.getFormat() != null) { ExcelFormat format = excell.getFormat(); CellStyle style = s_cellStyle.get(format.getBackgroundColor()); if (format.isDate()) { // for date create a new style style = getDateStyle("date", cell.getSheet(), font); XSSFCreationHelper createHelper = (XSSFCreationHelper) cell.getSheet().getWorkbook() .getCreationHelper(); style.setDataFormat(createHelper.createDataFormat().getFormat("MMMM dd, yyyy")); font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); font.setBold(false);//from w w w .ja v a 2 s .c om font.setFontHeightInPoints((short) 12); style.setFont(font); cell.setCellValue(new Date()); } if (style == null) { style = workbook.createCellStyle(); s_cellStyle.put(format.getBackgroundColor(), style); } if (format.getAlignment() > 0) { style.setAlignment(format.getAlignment()); } if (format.getBackgroundColor() != null && !IndexedColors.WHITE.equals(format.getBackgroundColor())) { style.setFillForegroundColor(format.getBackgroundColor().getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); } if (format.getTextColor() != null) { font.setColor(format.getTextColor().getIndex()); style.setFont(font); } if (format.isBold()) { font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); } if (format.getFontHeight() > 0) { font.setFontHeightInPoints(format.getFontHeight()); } if (format.isWrapText()) { style.setWrapText(true); } style.setFont(font); if (format.isHideText()) { invisibleFont.setColor(IndexedColors.WHITE.getIndex()); style.setFont(invisibleFont); } cell.setCellStyle(style); } else { // Let's set default formatting for free text cell IndexedColors defaultStyle = IndexedColors.AUTOMATIC; // we are using this index CellStyle style = s_cellStyle.get(defaultStyle); if (style == null) { style = workbook.createCellStyle(); s_cellStyle.put(defaultStyle, style); } style.setWrapText(true); cell.setCellStyle(style); } }
From source file:com.report.excel.ExcelToHtmlConverter.java
License:Apache License
void buildStyle_font(HSSFWorkbook workbook, StringBuilder style, HSSFFont font) { switch (font.getBoldweight()) { case HSSFFont.BOLDWEIGHT_BOLD: style.append("font-weight:bold;"); break;/* ww w. j a v a2 s .c om*/ case HSSFFont.BOLDWEIGHT_NORMAL: // by default, not not increase HTML size // style.append( "font-weight: normal; " ); break; } final HSSFColor fontColor = workbook.getCustomPalette().getColor(font.getColor()); if (fontColor != null) style.append("color: " + ExcelToHtmlUtils.getColor(fontColor) + "; "); if (font.getFontHeightInPoints() != 0) style.append("font-size:" + font.getFontHeightInPoints() + "pt;"); if (font.getItalic()) { style.append("font-style:italic;"); } }
From source file:domain.Excel.java
public void reporteSesionPeso() { // cargarLogo(); sheet.addMergedRegion(CellRangeAddress.valueOf("A1:E1")); sheet.addMergedRegion(CellRangeAddress.valueOf("A2:E2")); sheet.addMergedRegion(CellRangeAddress.valueOf("A3:E4")); /*Name REPORT*/ HSSFFont FontNameReport = wb.createFont(); FontNameReport.setFontName("Calibri"); FontNameReport.setFontHeightInPoints((short) 11); FontNameReport.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); FontNameReport.setColor(HSSFColor.DARK_RED.index); HSSFCellStyle styleNameReport = wb.createCellStyle(); styleNameReport.setAlignment(HSSFCellStyle.ALIGN_CENTER); styleNameReport.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); styleNameReport.setFont(FontNameReport); Row row = sheet.createRow(0);// w ww . ja v a 2 s .c o m Cell cell = row.createCell(0); cell.setCellValue("REPORTE DE SESIONES POR PESOS"); cell.setCellStyle(styleNameReport); /**/ /*DATE REPORT*/ HSSFFont FontDateReport = wb.createFont(); FontDateReport.setFontName("Calibri"); FontDateReport.setFontHeightInPoints((short) 10); FontDateReport.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); FontDateReport.setColor(HSSFColor.BLACK.index); HSSFCellStyle styleDateReport = wb.createCellStyle(); styleDateReport.setAlignment(HSSFCellStyle.ALIGN_CENTER); styleDateReport.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); styleDateReport.setFont(FontDateReport); row = sheet.createRow(1); cell = row.createCell(0); cell.setCellValue("FECHA DE REPORTE: " + formatoDateTime.format(new Date())); cell.setCellStyle(styleDateReport); /*Etiqueta parametro*/ HSSFFont FontParametroReport = wb.createFont(); FontParametroReport.setFontName("Calibri"); FontParametroReport.setFontHeightInPoints((short) 9); FontParametroReport.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); FontParametroReport.setColor(HSSFColor.BLACK.index); HSSFCellStyle styleParamReport = wb.createCellStyle(); styleParamReport.setAlignment(HSSFCellStyle.ALIGN_CENTER); styleParamReport.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); styleParamReport.setFont(FontParametroReport); row = sheet.createRow(2); cell = row.createCell(0); String etiqueta_parametro = ""; switch (tipo) { case 1: etiqueta_parametro = "Sesion de dia " + formatoDate.format(fecha_ini); break; case 2: etiqueta_parametro = "Sesiones del " + formatoDate.format(fecha_ini) + " al " + formatoDate.format(fecha_fin); break; case 3: etiqueta_parametro = "Sesiones del animal " + animal.arete_visual; break; } cell.setCellValue(etiqueta_parametro); cell.setCellStyle(styleParamReport); /**/ sheet.createRow(5).createCell(0).setCellValue("Arete Visual"); sheet.getRow(5).createCell(1).setCellValue("Arete Electronico"); sheet.getRow(5).createCell(2).setCellValue("Fecha"); sheet.getRow(5).createCell(3).setCellValue("Peso"); sheet.getRow(5).createCell(4).setCellValue("Corral"); sheet.setColumnWidth(0, 16 * Unidad); sheet.setColumnWidth(1, 16 * Unidad); sheet.setColumnWidth(2, 16 * Unidad); sheet.setColumnWidth(3, 16 * Unidad); sheet.setColumnWidth(4, 16 * Unidad); SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting(); //Condition 1: Cell Value Is greater than 70 (Blue Fill) ConditionalFormattingRule rule1 = sheetCF .createConditionalFormattingRule(CFRuleRecord.ComparisonOperator.GT, "1000"); PatternFormatting fill1 = rule1.createPatternFormatting(); fill1.setFillBackgroundColor(IndexedColors.DARK_RED.index); fill1.setFillPattern(PatternFormatting.SOLID_FOREGROUND); //Condition 2: Cell Value Is less than 50 (Green Fill) ConditionalFormattingRule rule2 = sheetCF .createConditionalFormattingRule(CFRuleRecord.ComparisonOperator.LT, "50"); PatternFormatting fill2 = rule2.createPatternFormatting(); fill2.setFillBackgroundColor(IndexedColors.DARK_RED.index); fill2.setFillPattern(PatternFormatting.SOLID_FOREGROUND); FontFormatting font = rule1.createFontFormatting(); font.setFontStyle(false, true); font.setFontColorIndex(IndexedColors.WHITE.index); CellRangeAddress[] regions = { CellRangeAddress.valueOf("A6:E6") }; sheetCF.addConditionalFormatting(regions, rule1, rule2); Integer fila_inicial = 6; for (int i = 0; i < this.t_tabla.getRowCount(); i++) { sheet.createRow(fila_inicial + i).createCell(0).setCellValue(t_tabla.getValueAt(i, 1).toString()); sheet.getRow(fila_inicial + i).getCell(0).setCellStyle(styleCenter); for (int j = 1; j < 5; j++) { sheet.getRow(fila_inicial + i).createCell(j).setCellValue(t_tabla.getValueAt(i, j + 1).toString()); sheet.getRow(fila_inicial + i).getCell(j).setCellStyle(styleCenter); } sheet.getRow(fila_inicial + i).getCell(3) .setCellValue(Double.parseDouble(t_tabla.getValueAt(i, 4).toString())); sheet.getRow(fila_inicial + i).getCell(3).setCellStyle(styleRight); } cargarLogo(); }