Java Code Examples for org.apache.poi.ss.usermodel.CellStyle#setBottomBorderColor()
The following examples show how to use
org.apache.poi.ss.usermodel.CellStyle#setBottomBorderColor() .
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: CellUtil.java From lams with GNU General Public License v2.0 | 8 votes |
/** * Sets the format properties of the given style based on the given map. * * @param style cell style * @param workbook parent workbook * @param properties map of format properties (String -> Object) * @see #getFormatProperties(CellStyle) */ private static void setFormatProperties(CellStyle style, Workbook workbook, Map<String, Object> properties) { style.setAlignment(getHorizontalAlignment(properties, ALIGNMENT)); style.setVerticalAlignment(getVerticalAlignment(properties, VERTICAL_ALIGNMENT)); style.setBorderBottom(getBorderStyle(properties, BORDER_BOTTOM)); style.setBorderLeft(getBorderStyle(properties, BORDER_LEFT)); style.setBorderRight(getBorderStyle(properties, BORDER_RIGHT)); style.setBorderTop(getBorderStyle(properties, BORDER_TOP)); style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR)); style.setDataFormat(getShort(properties, DATA_FORMAT)); style.setFillPattern(getFillPattern(properties, FILL_PATTERN)); style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR)); style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR)); style.setFont(workbook.getFontAt(getShort(properties, FONT))); style.setHidden(getBoolean(properties, HIDDEN)); style.setIndention(getShort(properties, INDENTION)); style.setLeftBorderColor(getShort(properties, LEFT_BORDER_COLOR)); style.setLocked(getBoolean(properties, LOCKED)); style.setRightBorderColor(getShort(properties, RIGHT_BORDER_COLOR)); style.setRotation(getShort(properties, ROTATION)); style.setTopBorderColor(getShort(properties, TOP_BORDER_COLOR)); style.setWrapText(getBoolean(properties, WRAP_TEXT)); }
Example 2
Source File: ExcelStyle.java From objectlabkit with Apache License 2.0 | 6 votes |
public CellStyle build(ExcelCell cell) { Optional<CellStyle> cs = cell.findStyle(hashCode()); if (cs.isPresent()) { return cs.get(); } CellStyle cellStyle = cell.cloneStyle(hashCode()); addFontFormat(cell, cellStyle); if (header) { cellStyle.setBorderBottom(BorderStyle.THIN); cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex()); cellStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex()); cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); } addFormat(cell, cellStyle); if (backgroundColour != null) { cellStyle.setFillForegroundColor(backgroundColour.getIndex()); cellStyle.setFillPattern(backgroundFillPatternType != null ? backgroundFillPatternType : FillPatternType.SOLID_FOREGROUND); } addAlignment(cellStyle); return cellStyle; }
Example 3
Source File: Exporter.java From ramus with GNU General Public License v3.0 | 5 votes |
private static CellStyle createBorderedStyle(Workbook wb) { CellStyle style = wb.createCellStyle(); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); return style; }
Example 4
Source File: ExportTimetableXLS.java From unitime with Apache License 2.0 | 5 votes |
protected CellStyle getMeetingFooterStyle(P p, P parent, Color bgColor) { if (bgColor == null) bgColor = Color.WHITE; String styleId = "meeting-footer-" + Integer.toHexString(bgColor.getRGB()); CellStyle style = iStyles.get(styleId); if (style == null) { style = iWorkbook.createCellStyle(); style.setBorderBottom(BorderStyle.THICK); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(BorderStyle.THICK); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderRight(BorderStyle.THICK); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.TOP); style.setFont(getFont(parent)); String colorId = Integer.toHexString(bgColor.getRGB()); Short color = iColors.get(colorId); if (color == null) { HSSFPalette palette = ((HSSFWorkbook)iWorkbook).getCustomPalette(); HSSFColor clr = palette.findSimilarColor(bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue()); color = (clr == null ? IndexedColors.WHITE.getIndex() : clr.getIndex()); iColors.put(colorId, color); } style.setFillForegroundColor(color); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setWrapText(true); iStyles.put(styleId, style); } return style; }
Example 5
Source File: AbstractStyleBuilder.java From bdf3 with Apache License 2.0 | 5 votes |
public CellStyle createBorderCellStyle(Workbook workbook, boolean showBorder) { CellStyle style = workbook.createCellStyle(); if (showBorder) { style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); } return style; }
Example 6
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 7
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 8
Source File: ColorUtils.java From Octopus with MIT License | 5 votes |
public static void setBorderColor(Workbook workbook, CellStyle cellStyle, Color[] color) { if (color == null) { return; } if (cellStyle instanceof XSSFCellStyle) { ((XSSFCellStyle) cellStyle).setTopBorderColor(new XSSFColor(color[0])); ((XSSFCellStyle) cellStyle).setRightBorderColor(new XSSFColor(color[1])); ((XSSFCellStyle) cellStyle).setBottomBorderColor(new XSSFColor(color[2])); ((XSSFCellStyle) cellStyle).setLeftBorderColor(new XSSFColor(color[3])); } else if (cellStyle instanceof HSSFCellStyle && workbook instanceof HSSFWorkbook) { cellStyle.setTopBorderColor(getSimilarColor((HSSFWorkbook) workbook, color[0]).getIndex()); cellStyle.setRightBorderColor(getSimilarColor((HSSFWorkbook) workbook, color[1]).getIndex()); cellStyle.setBottomBorderColor(getSimilarColor((HSSFWorkbook) workbook, color[2]).getIndex()); cellStyle.setLeftBorderColor(getSimilarColor((HSSFWorkbook) workbook, color[3]).getIndex()); } else { log.error("unknown font type"); } }
Example 9
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 10
Source File: XLSXWriter.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private static CellStyle createBorderedStyle(Workbook wb){ BorderStyle thin = BorderStyle.THIN; short black = IndexedColors.GREY_50_PERCENT.getIndex(); CellStyle style = wb.createCellStyle(); style.setBorderRight(thin); style.setRightBorderColor(black); style.setBorderBottom(thin); style.setBottomBorderColor(black); style.setBorderLeft(thin); style.setLeftBorderColor(black); style.setBorderTop(thin); style.setTopBorderColor(black); return style; }
Example 11
Source File: XLSXWriter.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private static CellStyle createBorderedStyle(Workbook wb){ BorderStyle thin = BorderStyle.THIN; short black = IndexedColors.GREY_50_PERCENT.getIndex(); CellStyle style = wb.createCellStyle(); style.setBorderRight(thin); style.setRightBorderColor(black); style.setBorderBottom(thin); style.setBottomBorderColor(black); style.setBorderLeft(thin); style.setLeftBorderColor(black); style.setBorderTop(thin); style.setTopBorderColor(black); return style; }
Example 12
Source File: FlatFileExtractor.java From Open-Lowcode with Eclipse Public License 2.0 | 5 votes |
/** * a utility class to create style for a border around a cell * * @param wb the workbook * @return the style to use to put border around a cell */ public static CellStyle createBorderedStyle(Workbook wb) { CellStyle style = wb.createCellStyle(); style.setBorderRight(BorderStyle.THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderBottom(BorderStyle.THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(BorderStyle.THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(BorderStyle.THIN); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); return style; }
Example 13
Source File: StyleUtil.java From easyexcel with Apache License 2.0 | 4 votes |
private static void buildCellStyle(Workbook workbook, CellStyle cellStyle, WriteCellStyle writeCellStyle, boolean isHead) { buildFont(workbook, cellStyle, writeCellStyle.getWriteFont(), isHead); if (writeCellStyle.getDataFormat() != null) { cellStyle.setDataFormat(writeCellStyle.getDataFormat()); } if (writeCellStyle.getHidden() != null) { cellStyle.setHidden(writeCellStyle.getHidden()); } if (writeCellStyle.getLocked() != null) { cellStyle.setLocked(writeCellStyle.getLocked()); } if (writeCellStyle.getQuotePrefix() != null) { cellStyle.setQuotePrefixed(writeCellStyle.getQuotePrefix()); } if (writeCellStyle.getHorizontalAlignment() != null) { cellStyle.setAlignment(writeCellStyle.getHorizontalAlignment()); } if (writeCellStyle.getWrapped() != null) { cellStyle.setWrapText(writeCellStyle.getWrapped()); } if (writeCellStyle.getVerticalAlignment() != null) { cellStyle.setVerticalAlignment(writeCellStyle.getVerticalAlignment()); } if (writeCellStyle.getRotation() != null) { cellStyle.setRotation(writeCellStyle.getRotation()); } if (writeCellStyle.getIndent() != null) { cellStyle.setIndention(writeCellStyle.getIndent()); } if (writeCellStyle.getBorderLeft() != null) { cellStyle.setBorderLeft(writeCellStyle.getBorderLeft()); } if (writeCellStyle.getBorderRight() != null) { cellStyle.setBorderRight(writeCellStyle.getBorderRight()); } if (writeCellStyle.getBorderTop() != null) { cellStyle.setBorderTop(writeCellStyle.getBorderTop()); } if (writeCellStyle.getBorderBottom() != null) { cellStyle.setBorderBottom(writeCellStyle.getBorderBottom()); } if (writeCellStyle.getLeftBorderColor() != null) { cellStyle.setLeftBorderColor(writeCellStyle.getLeftBorderColor()); } if (writeCellStyle.getRightBorderColor() != null) { cellStyle.setRightBorderColor(writeCellStyle.getRightBorderColor()); } if (writeCellStyle.getTopBorderColor() != null) { cellStyle.setTopBorderColor(writeCellStyle.getTopBorderColor()); } if (writeCellStyle.getBottomBorderColor() != null) { cellStyle.setBottomBorderColor(writeCellStyle.getBottomBorderColor()); } if (writeCellStyle.getFillPatternType() != null) { cellStyle.setFillPattern(writeCellStyle.getFillPatternType()); } if (writeCellStyle.getFillBackgroundColor() != null) { cellStyle.setFillBackgroundColor(writeCellStyle.getFillBackgroundColor()); } if (writeCellStyle.getFillForegroundColor() != null) { cellStyle.setFillForegroundColor(writeCellStyle.getFillForegroundColor()); } if (writeCellStyle.getShrinkToFit() != null) { cellStyle.setShrinkToFit(writeCellStyle.getShrinkToFit()); } }
Example 14
Source File: ExcelExport.java From frpMgr 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 15
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 16
Source File: QbeXLSExporter.java From Knowage-Server with GNU Affero General Public License v3.0 | 4 votes |
public CellStyle buildCellStyle(Sheet sheet) { CellStyle cellStyle = sheet.getWorkbook().createCellStyle(); cellStyle.setAlignment(CellStyle.ALIGN_RIGHT); cellStyle.setVerticalAlignment(CellStyle.ALIGN_CENTER); String cellBGColor = (String) this.getProperty(PROPERTY_CELL_BACKGROUND_COLOR); logger.debug("Cell background color : " + cellBGColor); short backgroundColorIndex = cellBGColor != null ? IndexedColors.valueOf(cellBGColor).getIndex() : IndexedColors.valueOf(DEFAULT_CELL_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_CELL_BORDER_COLOR); logger.debug("Cell border color : " + bordeBorderColor); short borderColorIndex = bordeBorderColor != null ? IndexedColors.valueOf(bordeBorderColor).getIndex() : IndexedColors.valueOf(DEFAULT_CELL_BORDER_COLOR).getIndex(); cellStyle.setLeftBorderColor(borderColorIndex); cellStyle.setRightBorderColor(borderColorIndex); cellStyle.setBottomBorderColor(borderColorIndex); cellStyle.setTopBorderColor(borderColorIndex); Font font = sheet.getWorkbook().createFont(); Short cellFontSize = (Short) this.getProperty(PROPERTY_CELL_FONT_SIZE); logger.debug("Cell font size : " + cellFontSize); short cellFontSizeShort = cellFontSize != null ? cellFontSize.shortValue() : DEFAULT_CELL_FONT_SIZE; font.setFontHeightInPoints(cellFontSizeShort); String fontName = (String) this.getProperty(PROPERTY_FONT_NAME); logger.debug("Font name : " + fontName); fontName = fontName != null ? fontName : DEFAULT_FONT_NAME; font.setFontName(fontName); String cellColor = (String) this.getProperty(PROPERTY_CELL_COLOR); logger.debug("Cell color : " + cellColor); short cellColorIndex = cellColor != null ? IndexedColors.valueOf(cellColor).getIndex() : IndexedColors.valueOf(DEFAULT_CELL_COLOR).getIndex(); font.setColor(cellColorIndex); cellStyle.setFont(font); return cellStyle; }
Example 17
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 18
Source File: CrosstabXLSExporter.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 19
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 20
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; }