Java Code Examples for org.apache.poi.ss.usermodel.Font#setBold()
The following examples show how to use
org.apache.poi.ss.usermodel.Font#setBold() .
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: ExcelFontFactory.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 7 votes |
/** * Returns the excel font stored in this wrapper. * * @param wrapper * the font wrapper that holds all font information from the repagination. * @return the created font. */ private Font createFont( final HSSFFontWrapper wrapper ) { final Font font = workbook.createFont(); font.setBold( wrapper.isBold() ); font.setColor( wrapper.getColorIndex() ); font.setFontName( wrapper.getFontName() ); font.setFontHeightInPoints( (short) wrapper.getFontHeight() ); font.setItalic( wrapper.isItalic() ); font.setStrikeout( wrapper.isStrikethrough() ); if ( wrapper.isUnderline() ) { font.setUnderline( Font.U_SINGLE ); } else { font.setUnderline( Font.U_NONE ); } return font; }
Example 2
Source File: XLSXWriter.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
/** * create a library of cell styles */ private static Map<String, CellStyle> createStyles(Workbook wb){ Map<String, CellStyle> styles = new HashMap<>(); CellStyle style; Font headerFont = wb.createFont(); headerFont.setBold(true); style = createBorderedStyle(wb); style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setVerticalAlignment(VerticalAlignment.TOP); style.setWrapText(true); style.setFont(headerFont); styles.put("header", style); style = createBorderedStyle(wb); style.setVerticalAlignment(VerticalAlignment.TOP); style.setWrapText(true); styles.put("body", style); return styles; }
Example 3
Source File: XLSXResponseWriter.java From lucene-solr with Apache License 2.0 | 6 votes |
SerialWriteWorkbook() { this.swb = new SXSSFWorkbook(100); this.sh = this.swb.createSheet(); this.rowIndex = 0; this.headerStyle = (XSSFCellStyle)swb.createCellStyle(); this.headerStyle.setFillBackgroundColor(IndexedColors.BLACK.getIndex()); //solid fill this.headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); Font headerFont = swb.createFont(); headerFont.setFontHeightInPoints((short)14); headerFont.setBold(true); headerFont.setColor(IndexedColors.WHITE.getIndex()); this.headerStyle.setFont(headerFont); }
Example 4
Source File: JU_FontReport.java From hy.common.report with Apache License 2.0 | 6 votes |
@Test public void test_FontOne() throws IOException { Workbook wb = new XSSFWorkbook(); Sheet sheet = wb.createSheet("sheet 01"); Row row = sheet.createRow(1); Font font = wb.createFont(); font.setBold(true); font.setColor((short) 13); font.setFontHeightInPoints((short) 24); font.setFontName("宋体"); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setFont(font); Cell cell = row.createCell(1); cell.setCellValue("这是测试字体格式的"); cell.setCellStyle(cellStyle); FileOutputStream fileOutputStream = new FileOutputStream("D://font.xlsx"); wb.write(fileOutputStream); wb.close(); }
Example 5
Source File: WorkbookContext.java From Octopus with MIT License | 6 votes |
public CellStyle getHeaderStyle(Field field) { CellStyle style = headerStyleMap.get(field); if (style == null) { style = book.createCellStyle(); Font font = book.createFont(); FieldCellStyle fieldCellStyle = field.getHeaderFieldCellStyle(); font.setFontHeightInPoints(fieldCellStyle.getFontSize()); font.setBold(fieldCellStyle.isBold()); ColorUtils.setColor(book, font, fieldCellStyle.getColor()); style.setFont(font); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); ColorUtils.setForegroundColor(book, style, fieldCellStyle.getForegroundColor()); setStyleBorder(style, fieldCellStyle.getBorder()); ColorUtils.setBorderColor(book, style, fieldCellStyle.getBorderColor()); cellStyleMap.put(field, style); return style; } return style; }
Example 6
Source File: WorkbookContext.java From Octopus with MIT License | 6 votes |
public CellStyle getCellStyle(Field field) { CellStyle style = cellStyleMap.get(field); if (style == null) { style = book.createCellStyle(); Font font = book.createFont(); FieldCellStyle fieldCellStyle = field.getFieldCellStyle(); font.setFontHeightInPoints(fieldCellStyle.getFontSize()); font.setBold(fieldCellStyle.isBold()); ColorUtils.setColor(book, font, fieldCellStyle.getColor()); style.setFont(font); ColorUtils.setForegroundColor(book, style, fieldCellStyle.getForegroundColor()); setStyleBorder(style, fieldCellStyle.getBorder()); ColorUtils.setBorderColor(book, style, fieldCellStyle.getBorderColor()); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); cellStyleMap.put(field, style); return style; } return style; }
Example 7
Source File: ExcelWriter.java From excel-boot with Artistic License 2.0 | 5 votes |
public CellStyle getHeaderCellStyle(SXSSFWorkbook workbook) { if (headCellStyle == null) { headCellStyle = workbook.getXSSFWorkbook().createCellStyle(); headCellStyle.setBorderTop(BorderStyle.NONE); headCellStyle.setBorderRight(BorderStyle.NONE); headCellStyle.setBorderBottom(BorderStyle.NONE); headCellStyle.setBorderLeft(BorderStyle.NONE); headCellStyle.setAlignment(HorizontalAlignment.CENTER); headCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); XSSFColor color = new XSSFColor(new java.awt.Color(217, 217, 217)); headCellStyle.setFillForegroundColor(color); headCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); Font font = workbook.createFont(); font.setFontName("微软雅黑"); font.setColor(IndexedColors.ROYAL_BLUE.index); font.setBold(true); headCellStyle.setFont(font); headCellStyle.setDataFormat(workbook.createDataFormat().getFormat("@")); } return headCellStyle; }
Example 8
Source File: ExcelUtil.java From RuoYi-Vue with MIT License | 5 votes |
/** * 创建表格样式 * * @param wb 工作薄对象 * @return 样式列表 */ private Map<String, CellStyle> createStyles(Workbook wb) { // 写入各条记录,每条记录对应excel表中的一行 Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); CellStyle style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setBorderRight(BorderStyle.THIN); style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setBorderLeft(BorderStyle.THIN); style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setBorderTop(BorderStyle.THIN); style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setBorderBottom(BorderStyle.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.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); Font headerFont = wb.createFont(); headerFont.setFontName("Arial"); headerFont.setFontHeightInPoints((short) 10); headerFont.setBold(true); headerFont.setColor(IndexedColors.WHITE.getIndex()); style.setFont(headerFont); styles.put("header", style); return styles; }
Example 9
Source File: ThDefaultCellStyle.java From myexcel with Apache License 2.0 | 5 votes |
@Override public CellStyle supply(Workbook workbook) { CellStyle style = workbook.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setBorderBottom(BorderStyle.THIN); style.setBorderRight(BorderStyle.THIN); style.setBorderTop(BorderStyle.THIN); style.setBorderLeft(BorderStyle.THIN); Font font = workbook.createFont(); font.setBold(true); style.setFont(font); return style; }
Example 10
Source File: SpreadsheetExporter.java From sakai with Educational Community License v2.0 | 5 votes |
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; }
Example 11
Source File: ExcelUtil.java From supplierShop with MIT License | 5 votes |
/** * 创建表格样式 * * @param wb 工作薄对象 * @return 样式列表 */ private Map<String, CellStyle> createStyles(Workbook wb) { // 写入各条记录,每条记录对应excel表中的一行 Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); CellStyle style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setBorderRight(BorderStyle.THIN); style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setBorderLeft(BorderStyle.THIN); style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setBorderTop(BorderStyle.THIN); style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setBorderBottom(BorderStyle.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.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); Font headerFont = wb.createFont(); headerFont.setFontName("Arial"); headerFont.setFontHeightInPoints((short) 10); headerFont.setBold(true); headerFont.setColor(IndexedColors.WHITE.getIndex()); style.setFont(headerFont); styles.put("header", style); return styles; }
Example 12
Source File: GridUtils.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static CellStyle createHeaderCellStyle( Workbook workbook ) { CellStyle headerCellStyle = workbook.createCellStyle(); Font headerFont = workbook.createFont(); headerFont.setBold( true ); headerFont.setFontHeightInPoints( ( short ) 10 ); headerFont.setFontName( FONT_ARIAL ); headerCellStyle.setFont( headerFont ); return headerCellStyle; }
Example 13
Source File: ExportUtils.java From tech-gallery with Apache License 2.0 | 5 votes |
private static void makeRowBold(HSSFWorkbook wb, Row row) { CellStyle style = wb.createCellStyle(); Font font = wb.createFont(); font.setBold(true); style.setFont(font); for (int i = 0; i < row.getLastCellNum(); i++) { row.getCell(i).setCellStyle(style); } }
Example 14
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 15
Source File: SpreadsheetExporter.java From sakai with Educational Community License v2.0 | 5 votes |
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; }
Example 16
Source File: ExportTimetableXLS.java From unitime with Apache License 2.0 | 5 votes |
protected Font getFont(boolean bold, boolean italic, boolean underline, Color c) { Short color = null; if (c == null) c = Color.BLACK; if (c != null) { String colorId = Integer.toHexString(c.getRGB()); color = iColors.get(colorId); if (color == null) { HSSFPalette palette = ((HSSFWorkbook)iWorkbook).getCustomPalette(); HSSFColor clr = palette.findSimilarColor(c.getRed(), c.getGreen(), c.getBlue()); color = (clr == null ? IndexedColors.BLACK.getIndex() : clr.getIndex()); iColors.put(colorId, color); } } String fontId = (bold ? "b" : "") + (italic ? "i" : "") + (underline ? "u" : "") + (color == null ? "" : color); Font font = iFonts.get(fontId); if (font == null) { font = iWorkbook.createFont(); font.setBold(bold); font.setItalic(italic); font.setUnderline(underline ? Font.U_SINGLE : Font.U_NONE); font.setColor(color); font.setFontHeightInPoints((short)iFontSize); font.setFontName(iFontName); iFonts.put(fontId, font); } return font; }
Example 17
Source File: XLSPrinter.java From unitime with Apache License 2.0 | 5 votes |
protected Font getFont(boolean bold, boolean italic, boolean underline, Color c) { Short color = null; if (c == null) c = Color.BLACK; if (c != null) { String colorId = Integer.toHexString(c.getRGB()); color = iColors.get(colorId); if (color == null) { HSSFPalette palette = ((HSSFWorkbook)iWorkbook).getCustomPalette(); HSSFColor clr = palette.findSimilarColor(c.getRed(), c.getGreen(), c.getBlue()); color = (clr == null ? IndexedColors.BLACK.getIndex() : clr.getIndex()); iColors.put(colorId, color); } } String fontId = (bold ? "b" : "") + (italic ? "i" : "") + (underline ? "u" : "") + (color == null ? "" : color); Font font = iFonts.get(fontId); if (font == null) { font = iWorkbook.createFont(); font.setBold(bold); font.setItalic(italic); font.setUnderline(underline ? Font.U_SINGLE : Font.U_NONE); font.setColor(color); font.setFontHeightInPoints((short)10); font.setFontName("Arial"); iFonts.put(fontId, font); } return font; }
Example 18
Source File: DataSetExportServicesImpl.java From dashbuilder with Apache License 2.0 | 4 votes |
private Map<String, CellStyle> createStyles(Workbook wb){ Map<String, CellStyle> styles = new HashMap<>(); CellStyle style; Font titleFont = wb.createFont(); titleFont.setFontHeightInPoints((short)12); titleFont.setBold(true); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setFillForegroundColor( IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setFont(titleFont); style.setWrapText(false); style.setBorderBottom(BorderStyle.THIN); style.setBottomBorderColor(IndexedColors.GREY_80_PERCENT.getIndex()); styles.put("header", style); Font cellFont = wb.createFont(); cellFont.setFontHeightInPoints((short)10); cellFont.setBold(true); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.RIGHT); style.setVerticalAlignment(VerticalAlignment.BOTTOM); style.setFont(cellFont); style.setWrapText(false); style.setDataFormat(wb.createDataFormat().getFormat( BuiltinFormats.getBuiltinFormat( 3 ))); styles.put("integer_number_cell", style); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.RIGHT); style.setVerticalAlignment(VerticalAlignment.BOTTOM); style.setFont(cellFont); style.setWrapText(false); style.setDataFormat(wb.createDataFormat().getFormat(BuiltinFormats.getBuiltinFormat(4))); styles.put("decimal_number_cell", style); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.LEFT); style.setVerticalAlignment(VerticalAlignment.BOTTOM); style.setFont(cellFont); style.setWrapText(false); style.setDataFormat( (short) BuiltinFormats.getBuiltinFormat("text") ); styles.put(TEXT_CELL, style); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.BOTTOM); style.setFont(cellFont); style.setWrapText(false); style.setDataFormat(wb.createDataFormat().getFormat( DateFormatConverter.convert( Locale.getDefault(), dateFormatPattern ))); styles.put("date_cell", style); return styles; }
Example 19
Source File: ReportExcelUtil.java From roncoo-education with MIT License | 4 votes |
public static void exportExcelForLecturerProfit(HttpServletResponse response, Page<LecturerProfitVO> result) throws IOException { // 创建一个workbook 对应一个excel文件 final SXSSFWorkbook workBook = new SXSSFWorkbook(); SXSSFSheet sheet = workBook.createSheet("讲师分润报表"); // 列名和列宽 String[] names = { "讲师名称", "银行卡号", "银行名称", "银行开户名", "讲师分润(元)", "平台分润(元)", "时间" };// 表头 Integer[] widths = { 25, 15, 15, 25, 25, 25, 25 };// 列宽 // 创建第一行 SXSSFRow row = sheet.createRow(0); // 设置第一行样式 CellStyle headStyle = workBook.createCellStyle(); headStyle.setAlignment(HorizontalAlignment.CENTER_SELECTION);// 水平居中 headStyle.setVerticalAlignment(VerticalAlignment.CENTER);// 垂直居中 // 设置第一行字体 Font headFont = workBook.createFont(); headFont.setBold(true); headStyle.setFont(headFont); // 设置第一行单元格内容、单元格样式 for (int i = 0; i < names.length; i++) { SXSSFCell cell = row.createCell(i); cell.setCellValue(names[i]); cell.setCellStyle(headStyle); sheet.setColumnWidth(i, widths[i] * 256); } // 从第二行开始遍历出分润记录表的数据,再写入单元格 SXSSFRow row1 = sheet.createRow(1); int r = 1; for (LecturerProfitVO bean : result.getList()) { row1 = sheet.createRow(r++); row1.createCell(0).setCellValue(bean.getLecturerVO().getLecturerName()); row1.createCell(1).setCellValue(bean.getBankCardNo()); row1.createCell(2).setCellValue(bean.getBankName()); row1.createCell(3).setCellValue(bean.getBankUserName()); row1.createCell(4).setCellValue(bean.getLecturerProfit().doubleValue()); row1.createCell(5).setCellValue(bean.getPlatformProfit().doubleValue()); row1.createCell(6).setCellValue(new SimpleDateFormat("yyyy/MM/dd").format(bean.getGmtCreate())); } try { workBook.write(response.getOutputStream()); response.getOutputStream().flush(); } catch (IOException e) { e.printStackTrace(); } finally { if (response.getOutputStream() != null) response.getOutputStream().close(); if (workBook != null) workBook.close(); } }
Example 20
Source File: ExcelUtil.java From lams with GNU General Public License v2.0 | 4 votes |
private static void initStyles(Workbook workbook) { Font defaultFont = workbook.createFont(); defaultFont.setFontName(DEFAULT_FONT_NAME); //create default style with default font name defaultStyle = workbook.createCellStyle(); defaultStyle.setFont(defaultFont); //create bold style boldStyle = workbook.createCellStyle(); Font boldFont = workbook.createFont(); boldFont.setBold(true); boldFont.setFontName(DEFAULT_FONT_NAME); boldStyle.setFont(boldFont); //create color style blueColor = workbook.createCellStyle(); blueColor.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex()); blueColor.setFillPattern(FillPatternType.SOLID_FOREGROUND); blueColor.setFont(defaultFont); redColor = workbook.createCellStyle(); redColor.setFillForegroundColor(IndexedColors.RED.getIndex()); redColor.setFillPattern(FillPatternType.SOLID_FOREGROUND); redColor.setFont(defaultFont); greenColor = workbook.createCellStyle(); greenColor.setFillForegroundColor(IndexedColors.LIME.getIndex()); greenColor.setFillPattern(FillPatternType.SOLID_FOREGROUND); Font whiteFont = workbook.createFont(); whiteFont.setColor(IndexedColors.WHITE.getIndex()); whiteFont.setFontName(DEFAULT_FONT_NAME); greenColor.setFont(whiteFont); yellowColor = workbook.createCellStyle(); yellowColor.setFillForegroundColor(IndexedColors.GOLD.getIndex()); yellowColor.setFillPattern(FillPatternType.SOLID_FOREGROUND); yellowColor.setFont(defaultFont); // create data formats floatFormat = workbook.createDataFormat().getFormat("0.00"); numberFormat = workbook.createDataFormat().getFormat("0"); dateFormat = (short)14;// built-in 0xe format - "m/d/yy" timeFormat = (short)19;// built-in 0x13 format - "h:mm:ss AM/PM" percentageFormat = workbook.createDataFormat().getFormat(FORMAT_PERCENTAGE); //create border style borderStyleLeftThin = workbook.createCellStyle(); borderStyleLeftThin.setBorderLeft(BorderStyle.THIN); borderStyleLeftThin.setFont(defaultFont); borderStyleLeftThick = workbook.createCellStyle(); borderStyleLeftThick.setBorderLeft(BorderStyle.THICK); borderStyleLeftThick.setFont(defaultFont); borderStyleRightThick = workbook.createCellStyle(); borderStyleRightThick.setBorderRight(BorderStyle.THICK); borderStyleRightThick.setFont(defaultFont); borderStyleLeftThinBoldFont = workbook.createCellStyle(); borderStyleLeftThinBoldFont.setBorderLeft(BorderStyle.THIN); borderStyleLeftThinBoldFont.setFont(boldFont); borderStyleLeftThickBoldFont = workbook.createCellStyle(); borderStyleLeftThickBoldFont.setBorderLeft(BorderStyle.THICK); borderStyleLeftThickBoldFont.setFont(boldFont); borderStyleRightThickBoldFont = workbook.createCellStyle(); borderStyleRightThickBoldFont.setBorderRight(BorderStyle.THICK); borderStyleRightThickBoldFont.setFont(boldFont); borderStyleBottomThin = workbook.createCellStyle(); borderStyleBottomThin.setBorderBottom(BorderStyle.THIN); borderStyleBottomThin.setFont(defaultFont); borderStyleBottomThinBoldFont = workbook.createCellStyle(); borderStyleBottomThinBoldFont.setBorderBottom(BorderStyle.THIN); borderStyleBottomThinBoldFont.setFont(boldFont); }