List of usage examples for org.apache.poi.ss.usermodel Font setFontName
void setFontName(String name);
From source file:com.catexpress.util.FormatosPOI.java
public CellStyle estiloHeader(Workbook wb, int tipo) { Font fuente = wb.createFont(); CreationHelper createHelper = wb.getCreationHelper(); fuente.setFontName("Calibri"); fuente.setBold(true);/*from w w w . j av a 2 s . c o m*/ if (tipo == TITULO || tipo == SUCURSAL || tipo == LABEL || tipo == FECHA) { fuente.setFontHeightInPoints((short) 16); } else if (tipo == USUARIO) { fuente.setFontHeightInPoints((short) 20); } CellStyle estiloCelda = wb.createCellStyle(); estiloCelda.setFont(fuente); if (tipo == TITULO || tipo == USUARIO || tipo == LABEL || tipo == FECHA) { estiloCelda.setFillForegroundColor(IndexedColors.WHITE.getIndex()); } else if (tipo == SUCURSAL) { estiloCelda.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); } estiloCelda.setFillPattern(CellStyle.SOLID_FOREGROUND); if (tipo == LABEL || tipo == FECHA) { estiloCelda.setWrapText(false); } else if (tipo == TITULO || tipo == SUCURSAL || tipo == USUARIO) { estiloCelda.setWrapText(true); } estiloCelda.setAlignment(HorizontalAlignment.CENTER); if (tipo == LABEL || tipo == FECHA) { estiloCelda.setVerticalAlignment(VerticalAlignment.BOTTOM); } else if (tipo == TITULO || tipo == SUCURSAL || tipo == USUARIO) { estiloCelda.setVerticalAlignment(VerticalAlignment.CENTER); } if (tipo == SUCURSAL) { estiloCelda.setBorderBottom(BorderStyle.MEDIUM); estiloCelda.setBorderTop(BorderStyle.MEDIUM); estiloCelda.setBorderLeft(BorderStyle.MEDIUM); estiloCelda.setBorderRight(BorderStyle.MEDIUM); } if (tipo == FECHA) { estiloCelda.setDataFormat(createHelper.createDataFormat().getFormat("dd \"de\" mmmm \"de\" yyyy")); } return estiloCelda; }
From source file:com.cms.utils.ExportExcell.java
private Comment getcellComment(FormatExcell item, Cell cell) { ExcellHeaderComment headerCommand = item.getHeaderCommand(); Drawing sSFPatriarch = sh.createDrawingPatriarch(); CreationHelper factory = cell.getSheet().getWorkbook().getCreationHelper(); ClientAnchor anchor = factory.createClientAnchor(); Comment comment1 = sSFPatriarch.createCellComment(anchor); anchor.setCol1(headerCommand.getRow1()); anchor.setCol2(headerCommand.getRow2()); anchor.setRow1(headerCommand.getColumn1()); anchor.setRow2(headerCommand.getColumn2()); anchor.setDx1(headerCommand.getDx1()); anchor.setDx2(headerCommand.getDx2()); anchor.setDy1(headerCommand.getDy1()); anchor.setDy2(headerCommand.getDy2()); RichTextString rtf1 = factory.createRichTextString(headerCommand.getValue()); Font font = wb.createFont(); font.setFontName("Arial"); font.setFontHeightInPoints((short) 10); font.setBoldweight(Font.BOLDWEIGHT_NORMAL); font.setColor(IndexedColors.RED.getIndex()); rtf1.applyFont(font);/*from w w w . ja v a2s .co m*/ comment1.setString(rtf1); comment1.setAuthor("Logistics"); // comment1.setColumn(cell.getColumnIndex()); // comment1.setRow(cell.getRowIndex()); return comment1; }
From source file:com.cms.utils.ExportExcell.java
private Comment getcellComment(Sheet sh, FormatExcell item, Cell cell) { ExcellHeaderComment headerCommand = item.getHeaderCommand(); Drawing sSFPatriarch = sh.createDrawingPatriarch(); CreationHelper factory = cell.getSheet().getWorkbook().getCreationHelper(); ClientAnchor anchor = factory.createClientAnchor(); Comment comment1 = sSFPatriarch.createCellComment(anchor); anchor.setCol1(headerCommand.getRow1()); anchor.setCol2(headerCommand.getRow2()); anchor.setRow1(headerCommand.getColumn1()); anchor.setRow2(headerCommand.getColumn2()); anchor.setDx1(headerCommand.getDx1()); anchor.setDx2(headerCommand.getDx2()); anchor.setDy1(headerCommand.getDy1()); anchor.setDy2(headerCommand.getDy2()); RichTextString rtf1 = factory.createRichTextString(headerCommand.getValue()); Font font = wb.createFont(); font.setFontName("Arial"); font.setFontHeightInPoints((short) 10); font.setBoldweight(Font.BOLDWEIGHT_NORMAL); font.setColor(IndexedColors.RED.getIndex()); rtf1.applyFont(font);/*from w ww .j a v a 2 s.c om*/ comment1.setString(rtf1); comment1.setAuthor("Logistics"); // comment1.setColumn(cell.getColumnIndex()); // comment1.setRow(cell.getRowIndex()); return comment1; }
From source file:com.crm.webapp.util.ExcelCustomExporter.java
License:Apache License
protected void createCustomFonts() { Font facetFont = wb.createFont(); Font cellFont = wb.createFont(); if (cellFontColor != null) { XSSFColor cellColor = new XSSFColor(cellFontColor); ((XSSFFont) cellFont).setColor(cellColor); }/*from w w w.j a va 2 s.co m*/ if (cellFontSize != null) { cellFont.setFontHeightInPoints((short) cellFontSize); } if (cellFontStyle.equalsIgnoreCase("BOLD")) { cellFont.setBoldweight(Font.BOLDWEIGHT_BOLD); } if (cellFontStyle.equalsIgnoreCase("ITALIC")) { cellFont.setItalic(true); } if (facetFontStyle.equalsIgnoreCase("BOLD")) { facetFont.setBoldweight(Font.BOLDWEIGHT_BOLD); } if (facetFontStyle.equalsIgnoreCase("ITALIC")) { facetFont.setItalic(true); } if (fontName != null) { cellFont.setFontName(fontName); facetFont.setFontName(fontName); } cellStyle.setFont(cellFont); if (facetBackground != null) { XSSFColor backgroundColor = new XSSFColor(facetBackground); ((XSSFCellStyle) facetStyle).setFillForegroundColor(backgroundColor); facetStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); } if (facetFontColor != null) { XSSFColor facetColor = new XSSFColor(facetFontColor); ((XSSFFont) facetFont).setColor(facetColor); } if (facetFontSize != null) { facetFont.setFontHeightInPoints((short) facetFontSize); } facetStyle.setFont(facetFont); facetStyle.setAlignment(CellStyle.ALIGN_CENTER); }
From source file:com.docdoku.server.export.ExcelGenerator.java
License:Open Source License
public File generateXLSResponse(QueryResult queryResult, Locale locale, String baseURL) { File excelFile = new File("export_parts.xls"); //Blank workbook XSSFWorkbook workbook = new XSSFWorkbook(); //Create a blank sheet XSSFSheet sheet = workbook.createSheet("Parts Data"); String header = StringUtils.join(queryResult.getQuery().getSelects(), ";"); String[] columns = header.split(";"); Map<Integer, String[]> data = new HashMap<>(); String[] headerFormatted = createXLSHeaderRow(header, columns, locale); data.put(1, headerFormatted);//from w w w . j a v a2s . c om Map<Integer, String[]> commentsData = new HashMap<>(); String[] headerComments = createXLSHeaderRowComments(header, columns); commentsData.put(1, headerComments); List<String> selects = queryResult.getQuery().getSelects(); int i = 1; for (QueryResultRow row : queryResult.getRows()) { i++; data.put(i, createXLSRow(selects, row, baseURL)); commentsData.put(i, createXLSRowComments(selects, row)); } //Iterate over data and write to sheet Set<Integer> keyset = data.keySet(); int rownum = 0; for (Integer key : keyset) { Row row = sheet.createRow(rownum++); String[] objArr = data.get(key); int cellnum = 0; for (String obj : objArr) { Cell cell = row.createCell(cellnum++); cell.setCellValue(obj); } CreationHelper factory = workbook.getCreationHelper(); Drawing drawing = sheet.createDrawingPatriarch(); String[] commentsObjArr = commentsData.get(key); cellnum = 0; for (String commentsObj : commentsObjArr) { if (commentsObj.length() > 0) { Cell cell = row.getCell(cellnum) != null ? row.getCell(cellnum) : row.createCell(cellnum); // When the comment box is visible, have it show in a 1x3 space ClientAnchor anchor = factory.createClientAnchor(); anchor.setCol1(cell.getColumnIndex()); anchor.setCol2(cell.getColumnIndex() + 1); anchor.setRow1(row.getRowNum()); anchor.setRow2(row.getRowNum() + 1); Comment comment = drawing.createCellComment(anchor); RichTextString str = factory.createRichTextString(commentsObj); comment.setString(str); // Assign the comment to the cell cell.setCellComment(comment); } cellnum++; } } // Define header style Font headerFont = workbook.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerFont.setFontHeightInPoints((short) 10); headerFont.setFontName("Courier New"); headerFont.setItalic(true); headerFont.setColor(IndexedColors.WHITE.getIndex()); CellStyle headerStyle = workbook.createCellStyle(); headerStyle.setFont(headerFont); headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); headerStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); // Set header style for (int j = 0; j < columns.length; j++) { Cell cell = sheet.getRow(0).getCell(j); cell.setCellStyle(headerStyle); if (cell.getCellComment() != null) { String comment = cell.getCellComment().getString().toString(); if (comment.equals(QueryField.CTX_PRODUCT_ID) || comment.equals(QueryField.CTX_SERIAL_NUMBER) || comment.equals(QueryField.PART_MASTER_NUMBER)) { for (int k = 0; k < queryResult.getRows().size(); k++) { Cell grayCell = sheet.getRow(k + 1).getCell(j) != null ? sheet.getRow(k + 1).getCell(j) : sheet.getRow(k + 1).createCell(j); grayCell.setCellStyle(headerStyle); } } } } try { //Write the workbook in file system FileOutputStream out = new FileOutputStream(excelFile); workbook.write(out); out.close(); } catch (Exception e) { LOGGER.log(Level.FINEST, null, e); } return excelFile; }
From source file:com.eyeq.pivot4j.export.poi.ExcelExporter.java
License:Common Public License
protected CellStyle createHeaderCellStyle() { CellStyle style = workbook.createCellStyle(); Font font = workbook.createFont(); font.setFontName(fontFamily); font.setFontHeightInPoints((short) fontSize); font.setBoldweight(Font.BOLDWEIGHT_BOLD); style.setFont(font);/*from w w w . j a v a 2s.c o m*/ style.setAlignment(CellStyle.ALIGN_LEFT); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); switch (format) { case XSSF: case SXSSF: ((XSSFCellStyle) style).setFillForegroundColor(new XSSFColor(Color.lightGray)); break; case HSSF: style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); break; default: assert false; } style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setBorderTop(CellStyle.BORDER_THIN); style.setBorderLeft(CellStyle.BORDER_THIN); style.setBorderRight(CellStyle.BORDER_THIN); style.setBorderBottom(CellStyle.BORDER_THIN); return style; }
From source file:com.eyeq.pivot4j.export.poi.ExcelExporter.java
License:Common Public License
protected CellStyle createValueCellStyle() { CellStyle style = workbook.createCellStyle(); Font font = workbook.createFont(); font.setFontName(fontFamily); font.setFontHeightInPoints((short) fontSize); font.setBoldweight(Font.BOLDWEIGHT_NORMAL); style.setFont(font);/*from ww w . j a v a 2 s.c om*/ style.setAlignment(CellStyle.ALIGN_RIGHT); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setBorderTop(CellStyle.BORDER_THIN); style.setBorderLeft(CellStyle.BORDER_THIN); style.setBorderRight(CellStyle.BORDER_THIN); style.setBorderBottom(CellStyle.BORDER_THIN); style.setDataFormat((short) 4); return style; }
From source file:com.eyeq.pivot4j.export.poi.ExcelExporter.java
License:Common Public License
protected CellStyle createAggregationCellStyle() { CellStyle style = workbook.createCellStyle(); Font font = workbook.createFont(); font.setFontName(fontFamily); font.setFontHeightInPoints((short) fontSize); font.setBoldweight(Font.BOLDWEIGHT_NORMAL); style.setFont(font);/*w w w. j a va 2 s . co m*/ style.setAlignment(CellStyle.ALIGN_RIGHT); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); switch (format) { case XSSF: case SXSSF: ((XSSFCellStyle) style).setFillForegroundColor(new XSSFColor(Color.lightGray)); break; case HSSF: style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); break; default: assert false; } style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setBorderTop(CellStyle.BORDER_THIN); style.setBorderLeft(CellStyle.BORDER_THIN); style.setBorderRight(CellStyle.BORDER_THIN); style.setBorderBottom(CellStyle.BORDER_THIN); style.setDataFormat((short) 4); return style; }
From source file:com.fengduo.spark.commons.file.excel.ExportExcel.java
License:Open Source License
/** * ?/* w w w .j a v a 2s .c o m*/ * * @param wb * @return ? */ private Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); CellStyle style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); Font titleFont = wb.createFont(); titleFont.setFontName("Arial"); titleFont.setFontHeightInPoints((short) 16); titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style.setFont(titleFont); styles.put("title", style); style = wb.createCellStyle(); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); Font dataFont = wb.createFont(); dataFont.setFontName("Arial"); dataFont.setFontHeightInPoints((short) 10); style.setFont(dataFont); styles.put("data", style); style = wb.createCellStyle(); style.cloneStyleFrom(styles.get("data")); style.setAlignment(CellStyle.ALIGN_LEFT); styles.put("data1", style); style = wb.createCellStyle(); style.cloneStyleFrom(styles.get("data")); style.setAlignment(CellStyle.ALIGN_CENTER); styles.put("data2", style); style = wb.createCellStyle(); style.cloneStyleFrom(styles.get("data")); style.setAlignment(CellStyle.ALIGN_RIGHT); styles.put("data3", style); style = wb.createCellStyle(); style.cloneStyleFrom(styles.get("data")); // style.setWrapText(true); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); Font headerFont = wb.createFont(); headerFont.setFontName("Arial"); headerFont.setFontHeightInPoints((short) 10); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerFont.setColor(IndexedColors.WHITE.getIndex()); style.setFont(headerFont); styles.put("header", style); return styles; }
From source file:com.funtl.framework.smoke.core.commons.excel.ExportExcel.java
License:Apache License
/** * ?//from www. ja v a 2 s.co m * * @param wb * @return ? */ private Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); CellStyle style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); // style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); // style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); Font titleFont = wb.createFont(); titleFont.setFontName("Arial"); titleFont.setFontHeightInPoints((short) 16); titleFont.setBold(true); // titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style.setFont(titleFont); styles.put("title", style); style = wb.createCellStyle(); style.setVerticalAlignment(VerticalAlignment.CENTER); // style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setBorderRight(BorderStyle.THIN); // style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setBorderLeft(BorderStyle.THIN); // style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setBorderTop(BorderStyle.THIN); // style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setBorderBottom(BorderStyle.THIN); // style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); Font dataFont = wb.createFont(); dataFont.setFontName("Arial"); dataFont.setFontHeightInPoints((short) 10); style.setFont(dataFont); styles.put("data", style); style = wb.createCellStyle(); style.cloneStyleFrom(styles.get("data")); style.setAlignment(HorizontalAlignment.LEFT); // style.setAlignment(CellStyle.ALIGN_LEFT); styles.put("data1", style); style = wb.createCellStyle(); style.cloneStyleFrom(styles.get("data")); style.setAlignment(HorizontalAlignment.CENTER); // style.setAlignment(CellStyle.ALIGN_CENTER); styles.put("data2", style); style = wb.createCellStyle(); style.cloneStyleFrom(styles.get("data")); style.setAlignment(HorizontalAlignment.RIGHT); // style.setAlignment(CellStyle.ALIGN_RIGHT); styles.put("data3", style); style = wb.createCellStyle(); style.cloneStyleFrom(styles.get("data")); // style.setWrapText(true); style.setAlignment(HorizontalAlignment.CENTER); // style.setAlignment(CellStyle.ALIGN_CENTER); style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); // style.setFillPattern(CellStyle.SOLID_FOREGROUND); Font headerFont = wb.createFont(); headerFont.setFontName("Arial"); headerFont.setFontHeightInPoints((short) 10); headerFont.setBold(true); // headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerFont.setColor(IndexedColors.WHITE.getIndex()); style.setFont(headerFont); styles.put("header", style); return styles; }