Refine search
protected XSSFCellStyle createStyle(XSSFColor color) { XSSFCellStyle style = workbook.createCellStyle(); if (color != null) { style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setFillForegroundColor(color); } style.setWrapText(true); style.setVerticalAlignment(VerticalAlignment.CENTER); return style; }
_cellXf.set(src.getCoreXf()); _cellStyleXf.set(src.getStyleXf()); } else { src.getCoreXf().toString(), DEFAULT_XML_OPTIONS ); src.getCTFill().toString(), DEFAULT_XML_OPTIONS ); addFill(fill); src.getCTBorder().toString(), DEFAULT_XML_OPTIONS ); addBorder(border); String fmt = src.getDataFormatString(); setDataFormat( (new XSSFDataFormat(_stylesSource)).getFormat(fmt) ); src.getFont().getCTFont().toString(), DEFAULT_XML_OPTIONS ); XSSFFont font = new XSSFFont(ctFont); font.registerTo(_stylesSource); setFont(font); } catch(XmlException e) { throw new POIXMLException(e);
protected void createStyles() { headerStyle = createStyle(null); Font headerFont = workbook.createFont(); headerFont.setBold(true); headerStyle.setFont(headerFont); defaultStyle = createStyle(null); scoreStyle = createStyle(null); scoreStyle.setAlignment(HorizontalAlignment.RIGHT); disabledScoreStyle = createStyle(DISABLED_COLOR); disabledScoreStyle.setAlignment(HorizontalAlignment.RIGHT); unavailableStyle = createStyle(UNAVAILABLE_COLOR); pinnedStyle = createStyle(PINNED_COLOR); hardPenaltyStyle = createStyle(HARD_PENALTY_COLOR); mediumPenaltyStyle = createStyle(MEDIUM_PENALTY_COLOR); softPenaltyStyle = createStyle(SOFT_PENALTY_COLOR); wrappedStyle = createStyle(null); republishedStyle = createStyle(REPUBLISHED_COLOR); }
errorOccured = true; XSSFCellStyle style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.RED.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); row.getCell(0).setCellStyle(style);
/** * 设置单元格的类型 * * @param attribute */ private void setCellType(Attributes attribute) { // 重置numFmtIndex,numFmtString的值 numFmtIndex = 0; numFmtString = ""; this.cellDataType = CellDataType.of(attribute.getValue(T_ATTR_VALUE)); // 获取单元格的xf索引,对应style.xml中cellXfs的子元素xf final String xfIndexStr = attribute.getValue(S_ATTR_VALUE); if (xfIndexStr != null) { int xfIndex = Integer.parseInt(xfIndexStr); XSSFCellStyle xssfCellStyle = stylesTable.getStyleAt(xfIndex); numFmtIndex = xssfCellStyle.getDataFormat(); numFmtString = xssfCellStyle.getDataFormatString(); if (numFmtString == null) { cellDataType = CellDataType.NULL; numFmtString = BuiltinFormats.getBuiltinFormat(numFmtIndex); } else if (org.apache.poi.ss.usermodel.DateUtil.isADateFormat(numFmtIndex, numFmtString)) { cellDataType = CellDataType.DATE; } } }
XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = wb.createSheet(); XSSFRow row = sheet.createRow(0); XSSFCell cell = row.createCell( 0); cell.setCellValue("custom XSSF colors"); XSSFCellStyle style1 = wb.createCellStyle(); style1.setFillForegroundColor(new XSSFColor(new java.awt.Color(128, 0, 128))); style1.setFillPattern(CellStyle.SOLID_FOREGROUND);
public static XSSFCellStyle getHeadCellStyle(XSSFWorkbook wb, XSSFFont font) { XSSFCellStyle headCellStyle = wb.createCellStyle(); headCellStyle.setFont(font); headCellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); headCellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); headCellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); headCellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); headCellStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); headCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); headCellStyle.setWrapText(false); headCellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); headCellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); return headCellStyle; }
XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = wb.createSheet("My Table Data"); XSSFCellStyle headerStyle = wb.createCellStyle(); headerStyle.setFillForegroundColor(IndexedColors.LEMON_CHIFFON.getIndex()); headerStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); headerStyle.setBorderTop(CellStyle.BORDER_THIN); headerStyle.setBorderBottom(CellStyle.BORDER_THIN); headerStyle.setBorderLeft(CellStyle.BORDER_THIN); headerStyle.setBorderRight(CellStyle.BORDER_THIN); headerStyle.setAlignment(HorizontalAlignment.CENTER); XSSFCellStyle cellStyle = wb.createCellStyle(); ha = HorizontalAlignment.RIGHT; cellStyle.setAlignment(ha); cell.setCellStyle(cellStyle);
XSSFCellStyle styleSubHeader = (XSSFCellStyle) wb.createCellStyle(); styleSubHeader.setFont(fontBold); styleSubHeader.setVerticalAlignment(CellStyle.VERTICAL_CENTER); styleSubHeader.setAlignment(CellStyle.ALIGN_CENTER); styleSubHeader.setFillForegroundColor(COLOR_ORANGE); styleSubHeader.setFillPattern(CellStyle.SOLID_FOREGROUND); styleSubHeader.setBorderBottom(CellStyle.BORDER_THIN); styleSubHeader.setBottomBorderColor(COLOR_GREY); styleSubHeader.setBorderLeft(CellStyle.BORDER_THIN); styleSubHeader.setLeftBorderColor(COLOR_GREY); styleSubHeader.setBorderRight(CellStyle.BORDER_THIN); styleSubHeader.setRightBorderColor(COLOR_GREY); styleSubHeader.setBorderTop(CellStyle.BORDER_THIN); styleSubHeader.setTopBorderColor(COLOR_GREY);
XSSFWorkbook wb = new XSSFWorkbook(); XSSFCellStyle cellStyle = wb.createCellStyle(); byte[] rgb = new byte[3]; rgb[0] = (byte) 242; // red rgb[1] = (byte) 220; // green rgb[2] = (byte) 219; // blue XSSFColor myColor = new XSSFColor(rgb); // #f2dcdb cellStyle.setFillForegroundColor(myColor); cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
CellStyle colStyle=cell.getColumn().getCustomCellStyle(); XSSFCellStyle style=(XSSFCellStyle)wb.createCellStyle(); style.setWrapText(true); String bgcolor=cellStyle.getBgcolor(); if(customStyle!=null && StringUtils.isNotBlank(customStyle.getBgcolor())){ style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setFillForegroundColor(buildXSSFColor(bgcolor)); BorderStyle borderStyle=getBorderStyle(topBorder); XSSFColor borderColor=buildXSSFColor(topBorder.getColor()); style.setTopBorderColor(borderColor); style.setBorderTop(borderStyle); BorderStyle borderStyle=getBorderStyle(bottomBorder); XSSFColor borderColor=buildXSSFColor(bottomBorder.getColor()); style.setBottomBorderColor(borderColor); style.setBorderBottom(borderStyle); BorderStyle borderStyle=getBorderStyle(leftBorder); XSSFColor borderColor=buildXSSFColor(leftBorder.getColor()); style.setLeftBorderColor(borderColor); style.setBorderLeft(borderStyle); BorderStyle borderStyle=getBorderStyle(rightBorder); XSSFColor borderColor=buildXSSFColor(rightBorder.getColor()); style.setRightBorderColor(borderColor); style.setBorderRight(borderStyle);
@Override public void prepareColumn(TableModel tableModel, XSSFSheet sheet, int col) { XSSFWorkbook wb = sheet.getWorkbook(); XSSFDataFormat df = wb.createDataFormat(); cellStyle = wb.createCellStyle(); XSSFFont f = wb.createFont(); f.setFontHeightInPoints((short) 12); f.setColor(IndexedColors.BLACK.getIndex()); cellStyle.setFont(f); cellStyle.setDataFormat(df.getFormat("m/d/yy")); }
protected void createExcelHeader(XSSFWorkbook workbook, XSSFSheet tableSheet) throws Exception { XSSFFont f = workbook.createFont(); f.setFontHeightInPoints((short) 12); f.setColor(IndexedColors.BLACK.getIndex()); XSSFDataFormat df = workbook.createDataFormat(); XSSFCellStyle cs = workbook.createCellStyle(); cs.setFont(f); cs.setDataFormat(df.getFormat("text")); cs.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); cs.setFillPattern(FillPatternType.SOLID_FOREGROUND); cs.setWrapText(true); XSSFCreationHelper createHelper = workbook.getCreationHelper(); XSSFRow rh = tableSheet.createRow(0); for (int i = 0; i < table.getColumnCount(); i++) { XSSFCell c1 = rh.createCell(i); c1.setCellStyle(cs); c1.setCellValue(createHelper.createRichTextString(table.getColumnName(i))); c1.setCellType(XSSFCell.CELL_TYPE_STRING); } }
@Override public void prepareColumn(TableModel tableModel, XSSFSheet sheet, int col) { XSSFWorkbook wb = sheet.getWorkbook(); XSSFDataFormat df = wb.createDataFormat(); cellStyle = wb.createCellStyle(); XSSFFont f = wb.createFont(); f.setFontHeightInPoints((short) 12); f.setBold(true); f.setColor(IndexedColors.BLACK.getIndex()); cellStyle.setFont(f); cellStyle.setDataFormat(df.getFormat("text")); cellStyle.setBorderTop(CellStyle.BORDER_THIN); cellStyle.setBorderColor(BorderSide.TOP, new XSSFColor(new Color(0, 0, 0))); cellStyle.setBorderRight(CellStyle.BORDER_THIN); cellStyle.setBorderColor(BorderSide.RIGHT, new XSSFColor(new Color(0, 0, 0))); cellStyle.setBorderBottom(CellStyle.BORDER_THIN); cellStyle.setBorderColor(BorderSide.BOTTOM, new XSSFColor(new Color(0, 0, 0))); cellStyle.setBorderLeft(CellStyle.BORDER_THIN); cellStyle.setBorderColor(BorderSide.LEFT, new XSSFColor(new Color(0, 0, 0))); }
private static void appendMentoringTitleRow(XSSFWorkbook wb, XSSFSheet sheet, int rowNum) { XSSFCellStyle titleCell = wb.createCellStyle(); Color titleCellGrey = new Color(0xECECEC); XSSFColor color = new XSSFColor(titleCellGrey); titleCell.setFillForegroundColor(color); titleCell.setBorderBottom(CellStyle.BORDER_MEDIUM); titleCell.setBorderTop(CellStyle.BORDER_MEDIUM); titleCell.setFillPattern(CellStyle.SOLID_FOREGROUND); Font titleFormat = wb.createFont(); titleFormat.setBoldweight(Font.BOLDWEIGHT_BOLD); titleFormat.setColor((short) 0x0); titleCell.setFont(titleFormat); XSSFRow row = sheet.createRow(rowNum); XSSFCell t1 = row.createCell(0); t1.setCellValue("Migration Service Estimate"); t1.setCellStyle(titleCell); XSSFCell t2 = row.createCell(1); t2.setCellStyle(titleCell); XSSFCell t3 = row.createCell(2); t3.setCellStyle(titleCell); XSSFCell t4 = row.createCell(3); t4.setCellStyle(titleCell); }
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; } }
private CellStyle backgroundStyle(SXSSFWorkbook workbook, Integer rgb, Font font) { XSSFCellStyle style = (XSSFCellStyle) workbook.createCellStyle(); if (rgb != null) { IndexedColorMap indexedColors = workbook.getXSSFWorkbook().getStylesSource().getIndexedColors(); XSSFColor color = new XSSFColor(convertRGB(rgb), indexedColors); style.setFillForegroundColor(color); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); } style.setBorderBottom(BorderStyle.THIN); style.setBorderTop(BorderStyle.THIN); style.setBorderLeft(BorderStyle.THIN); style.setBorderRight(BorderStyle.THIN); if (font != null) { style.setFont(font); } style.setWrapText(true); style.setVerticalAlignment(VerticalAlignment.CENTER); return style; }
CellStyle createHeaderStyle(Workbook wb){ XSSFCellStyle xstyle = (XSSFCellStyle)wb.createCellStyle(); XSSFColor header = new XSSFColor(new Color(79, 129, 189)); xstyle.setFillForegroundColor(header); xstyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); XSSFFont font = (XSSFFont)wb.createFont(); font.setColor(IndexedColors.WHITE.index); xstyle.setFont(font); return xstyle; }
private void configureStyle(XSSFCellStyle style) { XSSFFont font = style.getFont(); if (font.getBold()) { _style.bold(); if (font.getItalic()) { _style.italic(); if (style.getFillPatternEnum() == FillPatternType.SOLID_FOREGROUND) { XSSFColor fillForegroundXSSFColor = style .getFillForegroundXSSFColor(); String argb = fillForegroundXSSFColor.getARGBHex(); if (argb != null) { _style.background(argb.substring(2)); final XSSFFont stdFont = _stylesTable.getStyleAt(0).getFont(); final short fontHeight = style.getFont().getFontHeightInPoints(); if (stdFont.getFontHeightInPoints() != fontHeight) { _style.fontSize(fontHeight, SizeUnit.PT); XSSFColor fontColor = style.getFont().getXSSFColor(); if (fontColor != null) { String argbHex = fontColor.getARGBHex(); if (argbHex != null) { _style.foreground(argbHex.substring(2)); switch (style.getAlignmentEnum()) { case LEFT: _style.leftAligned();
XSSFCellStyle style1 = workbook.createCellStyle(); style1.setFillForegroundColor(new XSSFColor(new java.awt.Color(128, 0, 128))); style1.setFillPattern(CellStyle.SOLID_FOREGROUND); cell.setCellStyle(style1);