Java Code Examples for org.apache.poi.ss.usermodel.Font#setFontHeight()
The following examples show how to use
org.apache.poi.ss.usermodel.Font#setFontHeight() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UKExcelUtil.java From youkefu with Apache License 2.0 | 8 votes |
@SuppressWarnings("deprecation") private CellStyle baseCellStyle(){ CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); cellStyle.setWrapText(true); cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); Font font = wb.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); font.setFontName("宋体"); font.setFontHeight((short) 200); cellStyle.setFont(font); return cellStyle; }
Example 2
Source File: ExcelExporterProcess.java From youkefu with Apache License 2.0 | 8 votes |
private CellStyle baseCellStyle(){ CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); cellStyle.setWrapText(true); cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); Font font = wb.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); //font.setFontName("宋体"); font.setFontHeight((short) 200); cellStyle.setFont(font); return cellStyle; }
Example 3
Source File: ExcelExporterProcess.java From youkefu with Apache License 2.0 | 6 votes |
private CellStyle createContentStyle(){ CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 指定单元格居中对齐 cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 指定单元格垂直居中对齐 cellStyle.setWrapText(false);// 指定单元格自动换行 // 设置单元格字体 Font font = wb.createFont(); //font.setFontName("微软雅黑"); font.setFontHeight((short) 200); cellStyle.setFont(font); cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); return cellStyle ; }
Example 4
Source File: ExcelExporterProcess.java From youkefu with Apache License 2.0 | 6 votes |
/** * 首列样式 * @return */ private CellStyle createFirstCellStyle(){ CellStyle cellStyle = baseCellStyle(); Font font = wb.createFont(); //font.setFontName("微软雅黑"); font.setFontHeight((short) 180); cellStyle.setFont(font); cellStyle.setWrapText(false); cellStyle.setFillForegroundColor(HSSFColor.LIGHT_GREEN.index); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); return cellStyle; }
Example 5
Source File: StyleConfiguration.java From excel-rw-annotation with Apache License 2.0 | 6 votes |
/** * 设置通用的对齐居中、边框等 * * @param style 样式 */ private void setCommonStyle(CellStyle style) { // 设置单元格居中对齐、自动换行 style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setWrapText(true); //设置单元格字体 if (!buildInFontMap.containsKey(FONT_KEY)) { Font font = workbook.createFont(); //通用字体 font.setBoldweight(Font.BOLDWEIGHT_BOLD); font.setFontName("宋体"); font.setFontHeight((short) 200); buildInFontMap.put(FONT_KEY, font); } style.setFont(buildInFontMap.get(FONT_KEY)); // 设置单元格边框为细线条 style.setBorderLeft(CellStyle.BORDER_THIN); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBorderRight(CellStyle.BORDER_THIN); style.setBorderTop(CellStyle.BORDER_THIN); }
Example 6
Source File: AbstractSheet.java From tools with Apache License 2.0 | 6 votes |
/** * create the styles in the workbook */ private void createStyles(Workbook wb) { // create the styles this.checkboxStyle = wb.createCellStyle(); this.checkboxStyle.setAlignment(CellStyle.ALIGN_CENTER); this.checkboxStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); this.checkboxStyle.setBorderBottom(CellStyle.BORDER_THIN); this.checkboxStyle.setBorderLeft(CellStyle.BORDER_THIN); this.checkboxStyle.setBorderRight(CellStyle.BORDER_THIN); this.checkboxStyle.setBorderTop(CellStyle.BORDER_THIN); Font checkboxFont = wb.createFont(); checkboxFont.setFontHeight(FONT_SIZE); checkboxFont.setFontName(CHECKBOX_FONT_NAME); this.checkboxStyle.setFont(checkboxFont); this.dateStyle = wb.createCellStyle(); DataFormat df = wb.createDataFormat(); this.dateStyle.setDataFormat(df.getFormat("m/d/yy h:mm")); }
Example 7
Source File: UKExcelUtil.java From youkefu with Apache License 2.0 | 5 votes |
/** * 首列样式 * @return */ @SuppressWarnings("deprecation") private CellStyle createFirstCellStyle(){ CellStyle cellStyle = baseCellStyle(); Font font = wb.createFont(); font.setFontHeight((short) 180); cellStyle.setFont(font); cellStyle.setFillForegroundColor(HSSFColor.LIGHT_GREEN.index); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); return cellStyle; }
Example 8
Source File: UKExcelUtil.java From youkefu with Apache License 2.0 | 5 votes |
/** * 标题样式 * @return */ @SuppressWarnings("deprecation") private CellStyle createTitleCellStyle(){ CellStyle cellStyle = baseCellStyle(); Font font = wb.createFont(); font.setFontHeight((short) 180); cellStyle.setFont(font); cellStyle.setFillForegroundColor(HSSFColor.LIGHT_GREEN.index); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); return cellStyle; }
Example 9
Source File: UKExcelUtil.java From youkefu with Apache License 2.0 | 5 votes |
/** * 内容样式 * @return */ @SuppressWarnings("deprecation") private CellStyle createContentCellStyle(){ CellStyle cellStyle = baseCellStyle(); Font font = wb.createFont(); font.setFontHeight((short) 200); font.setBoldweight((short)0); cellStyle.setFont(font); return cellStyle; }
Example 10
Source File: AbstractSheet.java From tools with Apache License 2.0 | 5 votes |
public static CellStyle createHeaderStyle(Workbook wb) { CellStyle headerStyle = wb.createCellStyle(); headerStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); headerStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); Font headerFont = wb.createFont(); headerFont.setFontName("Arial"); headerFont.setFontHeight(FONT_SIZE); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerStyle.setFont(headerFont); headerStyle.setAlignment(CellStyle.ALIGN_CENTER); return headerStyle; }
Example 11
Source File: AbstractSheet.java From tools with Apache License 2.0 | 5 votes |
/** * create the styles in the workbook */ private void createStyles(Workbook wb) { // create the styles this.checkboxStyle = wb.createCellStyle(); this.checkboxStyle.setAlignment(HorizontalAlignment.CENTER); this.checkboxStyle.setVerticalAlignment(VerticalAlignment.CENTER); this.checkboxStyle.setBorderBottom(BorderStyle.THIN); this.checkboxStyle.setBorderLeft(BorderStyle.THIN); this.checkboxStyle.setBorderRight(BorderStyle.THIN); this.checkboxStyle.setBorderTop(BorderStyle.THIN); Font checkboxFont = wb.createFont(); checkboxFont.setFontHeight(FONT_SIZE); checkboxFont.setFontName(CHECKBOX_FONT_NAME); this.checkboxStyle.setFont(checkboxFont); this.dateStyle = wb.createCellStyle(); DataFormat df = wb.createDataFormat(); this.dateStyle.setDataFormat(df.getFormat("m/d/yy h:mm")); this.greenWrapped = createLeftWrapStyle(wb); this.greenWrapped.setFillForegroundColor(HSSFColor.LIGHT_GREEN.index); this.greenWrapped.setFillPattern(FillPatternType.SOLID_FOREGROUND); this.greenWrapped.setFillPattern(FillPatternType.SOLID_FOREGROUND); this.yellowWrapped = createLeftWrapStyle(wb); this.yellowWrapped.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index); this.yellowWrapped.setFillPattern(FillPatternType.SOLID_FOREGROUND); this.redWrapped = createLeftWrapStyle(wb); this.redWrapped.setFillForegroundColor(HSSFColor.RED.index); this.redWrapped.setFillPattern(FillPatternType.SOLID_FOREGROUND); }
Example 12
Source File: AbstractSheet.java From tools with Apache License 2.0 | 5 votes |
public static CellStyle createHeaderStyle(Workbook wb) { CellStyle headerStyle = wb.createCellStyle(); headerStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); Font headerFont = wb.createFont(); headerFont.setFontName("Arial"); headerFont.setFontHeight(FONT_SIZE); headerFont.setBold(true); headerStyle.setFont(headerFont); headerStyle.setAlignment(HorizontalAlignment.CENTER); headerStyle.setVerticalAlignment(VerticalAlignment.CENTER); headerStyle.setWrapText(true); return headerStyle; }
Example 13
Source File: UKExcelUtil.java From youkefu with Apache License 2.0 | 4 votes |
/** * 构建头部 */ @SuppressWarnings("deprecation") private void createHead(){ Row row = sheet.createRow(rowNum); // 设置第一行 Cell cell = row.createCell(0); row.setHeight((short) 1100); // 定义单元格为字符串类型 cell.setCellType(HSSFCell.ENCODING_UTF_16); cell.setCellValue(new XSSFRichTextString(this.headTitle)); // 指定合并区域 if(rowNum>0) { sheet.addMergedRegion(new CellRangeAddress(rowNum, rowNum,0,(cellNumber-1))); } CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 指定单元格居中对齐 cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 指定单元格垂直居中对齐 cellStyle.setWrapText(true);// 指定单元格自动换行 // 设置单元格字体 Font font = wb.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); font.setFontName("宋体"); font.setFontHeight((short) 400); cellStyle.setFont(font); cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); cell.setCellStyle(cellStyle); for(int i=1;i<this.cellNumber;i++){ Cell cell3= row.createCell(i); cell3.setCellStyle(cellStyle); } rowNum ++; }
Example 14
Source File: UKExcelUtil.java From youkefu with Apache License 2.0 | 4 votes |
/** * 构建副标题 */ @SuppressWarnings("deprecation") private void createSubHead(){ CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 指定单元格居中对齐 cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 指定单元格垂直居中对齐 cellStyle.setWrapText(true);// 指定单元格自动换行 // 设置单元格字体 Font font = wb.createFont(); //font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); font.setFontName("宋体"); font.setFontHeight((short) 180); cellStyle.setFont(font); cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); CellStyle leftStyle = wb.createCellStyle(); leftStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT); // 指定单元格居中对齐 leftStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 指定单元格垂直居中对齐 leftStyle.setWrapText(true);// 指定单元格自动换行 leftStyle.setFont(font); leftStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); leftStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); leftStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); leftStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); Row row1 = sheet.createRow(rowNum); row1.setHeight((short) 440); StringBuffer strb = new StringBuffer(); // if(false){ //增加 过滤器 // // }else{ // // } strb.append("报表生成日期:").append(getNowDate()) ; Cell cell2 = row1.createCell(0); cell2.setCellType(HSSFCell.ENCODING_UTF_16); cell2.setCellValue(new XSSFRichTextString(strb.toString())); cell2.setCellStyle(leftStyle); // 指定合并区域 if(rowNum>1) { sheet.addMergedRegion(new CellRangeAddress(rowNum, rowNum, 0, (cellNumber-1))); } for(int i=1;i<this.cellNumber;i++){ Cell cell3= row1.createCell(i); cell3.setCellStyle(cellStyle); } rowNum ++; }
Example 15
Source File: Util.java From Knowage-Server with GNU Affero General Public License v3.0 | 4 votes |
private static void copyCell(Cell oldCell, Cell newCell, List<CellStyle> styleList) { if (styleList != null) { if (oldCell.getSheet().getWorkbook() == newCell.getSheet().getWorkbook()) { newCell.setCellStyle(oldCell.getCellStyle()); } else { DataFormat newDataFormat = newCell.getSheet().getWorkbook().createDataFormat(); CellStyle newCellStyle = getSameCellStyle(oldCell, newCell, styleList); if (newCellStyle == null) { Font oldFont = oldCell.getSheet().getWorkbook().getFontAt(oldCell.getCellStyle().getFontIndex()); Font newFont = newCell.getSheet().getWorkbook().findFont(oldFont.getBoldweight(), oldFont.getColor(), oldFont.getFontHeight(), oldFont.getFontName(), oldFont.getItalic(), oldFont.getStrikeout(), oldFont.getTypeOffset(), oldFont.getUnderline()); if (newFont == null) { newFont = newCell.getSheet().getWorkbook().createFont(); newFont.setBoldweight(oldFont.getBoldweight()); newFont.setColor(oldFont.getColor()); newFont.setFontHeight(oldFont.getFontHeight()); newFont.setFontName(oldFont.getFontName()); newFont.setItalic(oldFont.getItalic()); newFont.setStrikeout(oldFont.getStrikeout()); newFont.setTypeOffset(oldFont.getTypeOffset()); newFont.setUnderline(oldFont.getUnderline()); newFont.setCharSet(oldFont.getCharSet()); } short newFormat = newDataFormat.getFormat(oldCell.getCellStyle().getDataFormatString()); newCellStyle = newCell.getSheet().getWorkbook().createCellStyle(); newCellStyle.setFont(newFont); newCellStyle.setDataFormat(newFormat); newCellStyle.setAlignment(oldCell.getCellStyle().getAlignment()); newCellStyle.setHidden(oldCell.getCellStyle().getHidden()); newCellStyle.setLocked(oldCell.getCellStyle().getLocked()); newCellStyle.setWrapText(oldCell.getCellStyle().getWrapText()); newCellStyle.setBorderBottom(oldCell.getCellStyle().getBorderBottom()); newCellStyle.setBorderLeft(oldCell.getCellStyle().getBorderLeft()); newCellStyle.setBorderRight(oldCell.getCellStyle().getBorderRight()); newCellStyle.setBorderTop(oldCell.getCellStyle().getBorderTop()); newCellStyle.setBottomBorderColor(oldCell.getCellStyle().getBottomBorderColor()); newCellStyle.setFillBackgroundColor(oldCell.getCellStyle().getFillBackgroundColor()); newCellStyle.setFillForegroundColor(oldCell.getCellStyle().getFillForegroundColor()); newCellStyle.setFillPattern(oldCell.getCellStyle().getFillPattern()); newCellStyle.setIndention(oldCell.getCellStyle().getIndention()); newCellStyle.setLeftBorderColor(oldCell.getCellStyle().getLeftBorderColor()); newCellStyle.setRightBorderColor(oldCell.getCellStyle().getRightBorderColor()); newCellStyle.setRotation(oldCell.getCellStyle().getRotation()); newCellStyle.setTopBorderColor(oldCell.getCellStyle().getTopBorderColor()); newCellStyle.setVerticalAlignment(oldCell.getCellStyle().getVerticalAlignment()); styleList.add(newCellStyle); } newCell.setCellStyle(newCellStyle); } } switch (oldCell.getCellType()) { case Cell.CELL_TYPE_STRING: newCell.setCellValue(oldCell.getStringCellValue()); break; case Cell.CELL_TYPE_NUMERIC: newCell.setCellValue(oldCell.getNumericCellValue()); break; case Cell.CELL_TYPE_BLANK: newCell.setCellType(Cell.CELL_TYPE_BLANK); break; case Cell.CELL_TYPE_BOOLEAN: newCell.setCellValue(oldCell.getBooleanCellValue()); break; case Cell.CELL_TYPE_ERROR: newCell.setCellErrorValue(oldCell.getErrorCellValue()); break; case Cell.CELL_TYPE_FORMULA: newCell.setCellFormula(oldCell.getCellFormula()); formulaInfoList.add(new FormulaInfo(oldCell.getSheet().getSheetName(), oldCell.getRowIndex(), oldCell.getColumnIndex(), oldCell.getCellFormula())); break; default: break; } }