Java Code Examples for org.apache.poi.ss.usermodel.Font#setBoldweight()
The following examples show how to use
org.apache.poi.ss.usermodel.Font#setBoldweight() .
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: ExportEventsImpl.java From neoscada with Eclipse Public License 1.0 | 6 votes |
private void makeHeader ( final List<Field> columns, final HSSFSheet sheet ) { final Font font = sheet.getWorkbook ().createFont (); font.setFontName ( "Arial" ); font.setBoldweight ( Font.BOLDWEIGHT_BOLD ); font.setColor ( HSSFColor.WHITE.index ); final CellStyle style = sheet.getWorkbook ().createCellStyle (); style.setFont ( font ); style.setFillForegroundColor ( HSSFColor.BLACK.index ); style.setFillPattern ( PatternFormatting.SOLID_FOREGROUND ); final HSSFRow row = sheet.createRow ( 0 ); for ( int i = 0; i < columns.size (); i++ ) { final Field field = columns.get ( i ); final HSSFCell cell = row.createCell ( i ); cell.setCellValue ( field.getHeader () ); cell.setCellStyle ( style ); } }
Example 4
Source File: AbstractStyleBuilder.java From bdf3 with Apache License 2.0 | 6 votes |
public void setCellStyleFont(Workbook workbook, CellStyle style, int i) { Font font = workbook.createFont(); if (i == 0) { // 正常 } else if (i == 4) { // 下划线 font.setUnderline(Font.U_SINGLE); style.setFont(font); } else if (i == 2) { // 倾斜 font.setItalic(true); style.setFont(font); } else if (i == 1) { // 加粗 font.setBoldweight(Font.BOLDWEIGHT_BOLD); style.setFont(font); } }
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: FontManager.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * Create a new POI Font based upon a BIRT style. * @param birtStyle * The BIRT style to base the Font upon. * @return * The Font whose attributes are described by the BIRT style. */ private Font createFont(BirtStyle birtStyle) { Font font = workbook.createFont(); // Family String fontName = smu.poiFontNameFromBirt(cleanupQuotes(birtStyle.getProperty( StyleConstants.STYLE_FONT_FAMILY ))); if( fontName == null ) { fontName = "Calibri"; } font.setFontName(fontName); // Size short fontSize = smu.fontSizeInPoints(cleanupQuotes(birtStyle.getProperty( StyleConstants.STYLE_FONT_SIZE ))); if(fontSize > 0) { font.setFontHeightInPoints(fontSize); } // Weight short fontWeight = smu.poiFontWeightFromBirt(cleanupQuotes(birtStyle.getProperty( StyleConstants.STYLE_FONT_WEIGHT ))); if(fontWeight > 0) { font.setBoldweight(fontWeight); } // Style String fontStyle = cleanupQuotes(birtStyle.getProperty( StyleConstants.STYLE_FONT_STYLE ) ); if( CSSConstants.CSS_ITALIC_VALUE.equals(fontStyle) || CSSConstants.CSS_OBLIQUE_VALUE.equals(fontStyle)) { font.setItalic(true); } // Underline String fontUnderline = cleanupQuotes(birtStyle.getProperty( StyleConstants.STYLE_TEXT_UNDERLINE ) ); if( CSSConstants.CSS_UNDERLINE_VALUE.equals(fontUnderline) ) { font.setUnderline(FontUnderline.SINGLE.getByteValue()); } // Colour smu.addColourToFont( workbook, font, cleanupQuotes( birtStyle.getProperty( StyleConstants.STYLE_COLOR ) ) ); fonts.add(new FontPair(birtStyle, font)); return font; }
Example 7
Source File: DefaultXlsTableExporter.java From olat with Apache License 2.0 | 5 votes |
private CellStyle getHeaderCellStyle(final Workbook wb) { CellStyle cellStyle = wb.createCellStyle(); Font boldFont = wb.createFont(); boldFont.setBoldweight(Font.BOLDWEIGHT_BOLD); cellStyle.setFont(boldFont); return cellStyle; }
Example 8
Source File: DefaultXlsTableExporter.java From olat with Apache License 2.0 | 5 votes |
private CellStyle getHeaderCellStyle(final Workbook wb) { CellStyle cellStyle = wb.createCellStyle(); Font boldFont = wb.createFont(); boldFont.setBoldweight(Font.BOLDWEIGHT_BOLD); cellStyle.setFont(boldFont); return cellStyle; }
Example 9
Source File: ExcelLogWriter.java From axelor-open-suite with GNU Affero General Public License v3.0 | 5 votes |
private CellStyle setStyle() { CellStyle cellStyle = workbook.createCellStyle(); Font font = workbook.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); 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: ExcelHandler.java From development with Apache License 2.0 | 5 votes |
private static CellStyle initializeSheet(Workbook wb, Sheet sheet) { PrintSetup printSetup = sheet.getPrintSetup(); printSetup.setLandscape(true); sheet.setFitToPage(true); sheet.setHorizontallyCenter(true); CellStyle styleTitle; Font titleFont = wb.createFont(); titleFont.setFontHeightInPoints((short) 12); titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD); titleFont.setFontName("Arial"); styleTitle = wb.createCellStyle(); styleTitle.setFont(titleFont); return styleTitle; }
Example 12
Source File: CrosstabXLSExporter.java From Knowage-Server with GNU Affero General Public License v3.0 | 5 votes |
public CellStyle buildDimensionCellStyle(Sheet sheet) { CellStyle cellStyle = sheet.getWorkbook().createCellStyle(); cellStyle.setAlignment(CellStyle.ALIGN_CENTER); cellStyle.setVerticalAlignment(CellStyle.ALIGN_CENTER); String headerBGColor = (String) this.getProperty(PROPERTY_DIMENSION_NAME_BACKGROUND_COLOR); logger.debug("Header background color : " + headerBGColor); short backgroundColorIndex = headerBGColor != null ? IndexedColors.valueOf(headerBGColor).getIndex() : IndexedColors.valueOf( DEFAULT_DIMENSION_NAME_BACKGROUND_COLOR).getIndex(); cellStyle.setFillForegroundColor(backgroundColorIndex); cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); cellStyle.setBorderBottom(CellStyle.BORDER_THIN); cellStyle.setBorderLeft(CellStyle.BORDER_THIN); cellStyle.setBorderRight(CellStyle.BORDER_THIN); cellStyle.setBorderTop(CellStyle.BORDER_THIN); String bordeBorderColor = (String) this.getProperty(PROPERTY_HEADER_BORDER_COLOR); logger.debug("Header border color : " + bordeBorderColor); short borderColorIndex = bordeBorderColor != null ? IndexedColors.valueOf(bordeBorderColor).getIndex() : IndexedColors.valueOf( DEFAULT_HEADER_BORDER_COLOR).getIndex(); cellStyle.setLeftBorderColor(borderColorIndex); cellStyle.setRightBorderColor(borderColorIndex); cellStyle.setBottomBorderColor(borderColorIndex); cellStyle.setTopBorderColor(borderColorIndex); Font font = sheet.getWorkbook().createFont(); Short headerFontSize = (Short) this.getProperty(PROPERTY_HEADER_FONT_SIZE); logger.debug("Header font size : " + headerFontSize); short headerFontSizeShort = headerFontSize != null ? headerFontSize.shortValue() : DEFAULT_HEADER_FONT_SIZE; font.setFontHeightInPoints(headerFontSizeShort); String fontName = (String) this.getProperty(PROPERTY_FONT_NAME); logger.debug("Font name : " + fontName); fontName = fontName != null ? fontName : DEFAULT_FONT_NAME; font.setFontName(fontName); String color = (String) this.getProperty(PROPERTY_DIMENSION_NAME_COLOR); logger.debug("Dimension color : " + color); short colorIndex = bordeBorderColor != null ? IndexedColors.valueOf(color).getIndex() : IndexedColors.valueOf(DEFAULT_DIMENSION_NAME_COLOR).getIndex(); font.setColor(colorIndex); font.setBoldweight(Font.BOLDWEIGHT_BOLD); font.setItalic(true); cellStyle.setFont(font); return cellStyle; }
Example 13
Source File: ExcelUtils.java From mySpringBoot with Apache License 2.0 | 5 votes |
/** * 设置表头 * * @param wb * @param sheet * @param titles * @return */ private static int writeTitlesToExcel(XSSFWorkbook wb, Sheet sheet, List<String> titles) { int rowIndex = 0; int colIndex = 0; Font titleFont = wb.createFont(); //设置字体 titleFont.setFontName("simsun"); //设置粗体 titleFont.setBoldweight(Short.MAX_VALUE); //设置字号 titleFont.setFontHeightInPoints((short) 14); //设置颜色 titleFont.setColor(IndexedColors.BLACK.index); XSSFCellStyle titleStyle = wb.createCellStyle(); //水平居中 titleStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER); //垂直居中 titleStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); //设置图案颜色 titleStyle.setFillForegroundColor(new XSSFColor(new Color(182, 184, 192))); //设置图案样式 titleStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); titleStyle.setFont(titleFont); setBorder(titleStyle, BorderStyle.THIN, new XSSFColor(new Color(0, 0, 0))); Row titleRow = sheet.createRow(rowIndex); titleRow.setHeightInPoints(25); colIndex = 0; for (String field : titles) { Cell cell = titleRow.createCell(colIndex); cell.setCellValue(field); cell.setCellStyle(titleStyle); colIndex++; } rowIndex++; return rowIndex; }
Example 14
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 15
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 16
Source File: HRExcelBuilder.java From Spring-MVC-Blueprints with MIT License | 4 votes |
@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()); } }
Example 17
Source File: ExportExcel.java From Shop-for-JavaWeb with MIT License | 4 votes |
/** * 创建表格样式 * @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; }
Example 18
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; } }
Example 19
Source File: QbeXLSExporter.java From Knowage-Server with GNU Affero General Public License v3.0 | 4 votes |
public CellStyle buildHeaderCellStyle(Sheet sheet) { CellStyle cellStyle = sheet.getWorkbook().createCellStyle(); cellStyle.setAlignment(CellStyle.ALIGN_LEFT); cellStyle.setVerticalAlignment(CellStyle.ALIGN_CENTER); String headerBGColor = (String) this.getProperty(PROPERTY_HEADER_BACKGROUND_COLOR); logger.debug("Header background color : " + headerBGColor); short backgroundColorIndex = headerBGColor != null ? IndexedColors.valueOf(headerBGColor).getIndex() : IndexedColors.valueOf(DEFAULT_HEADER_BACKGROUND_COLOR).getIndex(); cellStyle.setFillForegroundColor(backgroundColorIndex); cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); cellStyle.setBorderBottom(CellStyle.BORDER_THIN); cellStyle.setBorderLeft(CellStyle.BORDER_THIN); cellStyle.setBorderRight(CellStyle.BORDER_THIN); cellStyle.setBorderTop(CellStyle.BORDER_THIN); String bordeBorderColor = (String) this.getProperty(PROPERTY_HEADER_BORDER_COLOR); logger.debug("Header border color : " + bordeBorderColor); short borderColorIndex = bordeBorderColor != null ? IndexedColors.valueOf(bordeBorderColor).getIndex() : IndexedColors.valueOf(DEFAULT_HEADER_BORDER_COLOR).getIndex(); cellStyle.setLeftBorderColor(borderColorIndex); cellStyle.setRightBorderColor(borderColorIndex); cellStyle.setBottomBorderColor(borderColorIndex); cellStyle.setTopBorderColor(borderColorIndex); Font font = sheet.getWorkbook().createFont(); Short headerFontSize = (Short) this.getProperty(PROPERTY_HEADER_FONT_SIZE); logger.debug("Header font size : " + headerFontSize); short headerFontSizeShort = headerFontSize != null ? headerFontSize.shortValue() : DEFAULT_HEADER_FONT_SIZE; font.setFontHeightInPoints(headerFontSizeShort); String fontName = (String) this.getProperty(PROPERTY_FONT_NAME); logger.debug("Font name : " + fontName); fontName = fontName != null ? fontName : DEFAULT_FONT_NAME; font.setFontName(fontName); String headerColor = (String) this.getProperty(PROPERTY_HEADER_COLOR); logger.debug("Header color : " + headerColor); short headerColorIndex = bordeBorderColor != null ? IndexedColors.valueOf(headerColor).getIndex() : IndexedColors.valueOf(DEFAULT_HEADER_COLOR).getIndex(); font.setColor(headerColorIndex); font.setBoldweight(Font.BOLDWEIGHT_BOLD); cellStyle.setFont(font); return cellStyle; }
Example 20
Source File: CellStyles.java From xcelite with Apache License 2.0 | 4 votes |
private void createBoldStyle() { boldStyle = wb.createCellStyle(); Font font = wb.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); boldStyle.setFont(font); }