/** * Returns the default title style. Obtained from: * http://svn.apache.org/repos/asf/poi * /trunk/src/examples/src/org/apache/poi/ss/examples/TimesheetDemo.java * * @param wb the wb * @return the cell style */ protected CellStyle defaultTitleCellStyle(final Workbook wb) { CellStyle style; final Font titleFont = wb.createFont(); titleFont.setFontHeightInPoints((short) 18); titleFont.setBold(true); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setFont(titleFont); return style; }
/** * Returns the default header style. Obtained from: * http://svn.apache.org/repos/asf/poi * /trunk/src/examples/src/org/apache/poi/ss/examples/TimesheetDemo.java * * @param wb the wb * @return the cell style */ protected CellStyle defaultHeaderCellStyle(final Workbook wb) { CellStyle style; final Font monthFont = wb.createFont(); monthFont.setFontHeightInPoints((short) 11); monthFont.setColor(IndexedColors.WHITE.getIndex()); style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setFont(monthFont); style.setWrapText(true); return style; }
public CellStyle createIndentationCellStyle(Workbook workbook, int s) { CellStyle dataStyle1 = this.createBorderCellStyle(workbook, true); Font dataFont = workbook.createFont(); dataFont.setColor((short) 12); dataFont.setFontHeightInPoints((short) 10); dataStyle1.setFillPattern(FillPatternType.SOLID_FOREGROUND); dataStyle1.setFillForegroundColor((short) 11); dataStyle1.setFont(dataFont); dataStyle1.setVerticalAlignment(VerticalAlignment.CENTER); dataStyle1.setAlignment(HorizontalAlignment.LEFT); dataStyle1.setIndention(Short.valueOf(String.valueOf((s)))); return dataStyle1; }
private HSSFCellStyle createHSSFCellStyle(Workbook wb, int[] bgColor, int[] fontColor, int fontSize) { HSSFWorkbook workbook = (HSSFWorkbook) wb; HSSFPalette palette = workbook.getCustomPalette(); palette.setColorAtIndex((short) 9, (byte) fontColor[0], (byte) fontColor[1], (byte) fontColor[2]); palette.setColorAtIndex((short) 10, (byte) bgColor[0], (byte) bgColor[1], (byte) bgColor[2]); HSSFFont titleFont = workbook.createFont(); titleFont.setCharSet(HSSFFont.DEFAULT_CHARSET); titleFont.setFontName("宋体"); titleFont.setColor((short) 9); titleFont.setBold(true); titleFont.setFontHeightInPoints((short) fontSize); HSSFCellStyle titleStyle = (HSSFCellStyle) createBorderCellStyle(workbook, true); titleStyle.setFont(titleFont); titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); titleStyle.setFillForegroundColor((short) 10); titleStyle.setAlignment(HorizontalAlignment.CENTER); titleStyle.setVerticalAlignment(VerticalAlignment.CENTER); return titleStyle; }
public CellStyle builderValueCellStyle(ReportForm reportFormModel, Workbook workbook) { List<ReportFormData> list = reportFormModel.getListReportFormDataModel(); ReportFormData reportFormDataModel; if (list.size() > 0) { reportFormDataModel = list.get(0); int dataAlign = reportFormDataModel.getDataAlign(); int dataStyle = reportFormDataModel.getDataStyle(); CellStyle valueStyle = createBorderCellStyle(workbook, reportFormModel.isShowBorder()); setCellStyleAligment(valueStyle, dataAlign); valueStyle.setVerticalAlignment(VerticalAlignment.CENTER); this.setCellStyleFont(workbook, valueStyle, dataStyle); return valueStyle; } return null; }
protected HSSFCellStyle getLoadedCellStyle( FillPatternType mode, short backcolor, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, short rotation, HSSFFont font, BoxStyle box, boolean isWrapText, boolean isCellLocked, boolean isCellHidden, boolean isShrinkToFit ) { StyleInfo style = new StyleInfo(mode, backcolor, horizontalAlignment, verticalAlignment, rotation, font, box, isWrapText, isCellLocked, isCellHidden, isShrinkToFit); return getLoadedCellStyle(style); }
public StyleInfo( FillPatternType mode, short backcolor, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, short rotation, HSSFFont font, JRExporterGridCell gridCell, boolean wrapText, boolean cellLocked, boolean cellHidden, boolean shrinkToFit ) { this(mode, backcolor, horizontalAlignment, verticalAlignment, rotation, font, (gridCell == null ? null : new BoxStyle(gridCell)), wrapText, cellLocked, cellHidden, shrinkToFit); }
/** * 表头条件 * @param sheet * @param t * @param cellCount * @return */ void writeCondtions(HSSFSheet sheet){ T t = getConditions(); if (t!=null) { HSSFRow row = sheet.createRow(getRowNumber()); row.setHeight((short) 500); CellRangeAddress cra = new CellRangeAddress(getRowNumber(), getRowNumber(), 0, getColumnJson().size()); sheet.addMergedRegion(cra); HSSFCell cell = row.createCell(0); HSSFCellStyle style = cell.getCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setWrapText(true); cell.setCellStyle(style); setCellValue(cell, formatCondition(t)); addRowNumber(); } }
public static VAlign poiToVAlign(VerticalAlignment alignment) { switch (alignment) { case TOP: return VAlign.ALIGN_TOP; case CENTER: return VAlign.ALIGN_MIDDLE; case BOTTOM: return VAlign.ALIGN_BOTTOM; case JUSTIFY: return VAlign.ALIGN_JUSTIFY; case DISTRIBUTED: return VAlign.ALIGN_MIDDLE; default: LOGGER.warn("Unknown value for vertical algnment: {}", alignment); return VAlign.ALIGN_MIDDLE; } }
/** * 普通单元格样式 * * @param workbook * @return * @author 阳自然 */ private static CellStyle getCellStyle(Workbook workbook) { // 创建格式 普通格式 CellStyle cellStyle = workbook.createCellStyle(); cellStyle.setFont(getFont(workbook, null)); // 单元格边框 cellStyle.setBorderBottom(BorderStyle.THIN); cellStyle.setBorderTop(BorderStyle.THIN); cellStyle.setBorderLeft(BorderStyle.THIN); cellStyle.setBorderRight(BorderStyle.THIN); // 垂直居中对齐 cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); return cellStyle; }
/** * Returns the default totals row style for Double data. Obtained from: * http://svn.apache.org/repos/asf/poi * /trunk/src/examples/src/org/apache/poi/ss/examples/TimesheetDemo.java * * @param wb the wb * @return the cell style */ protected CellStyle defaultTotalsDoubleCellStyle(final Workbook wb) { CellStyle style; style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setDataFormat(doubleDataFormat); return style; }
/** * Returns the default totals row style for Integer data. Obtained from: * http://svn.apache.org/repos/asf/poi * /trunk/src/examples/src/org/apache/poi/ss/examples/TimesheetDemo.java * * @param wb the wb * @return the cell style */ protected CellStyle defaultTotalsIntegerCellStyle(final Workbook wb) { CellStyle style; style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setDataFormat(integerDataFormat); return style; }
public CellStyle builderLabelCellStyle(ReportForm reportFormModel, Workbook workbook) { List<ReportFormData> list = reportFormModel.getListReportFormDataModel(); ReportFormData reportFormDataModel; if (list.size() > 0) { reportFormDataModel = list.get(0); int labelAlign = reportFormDataModel.getLabelAlign(); CellStyle labelStyle = createBorderCellStyle(workbook, reportFormModel.isShowBorder()); setCellStyleAligment(labelStyle, labelAlign); labelStyle.setVerticalAlignment(VerticalAlignment.CENTER); return labelStyle; } return null; }
private XSSFCellStyle createXSSFCellStyle(Workbook wb, int[] bgColor, int[] fontColor, int fontSize) { SXSSFWorkbook workbook = (SXSSFWorkbook) wb; XSSFFont titleFont = (XSSFFont) workbook.createFont(); titleFont.setCharSet(HSSFFont.DEFAULT_CHARSET); titleFont.setFontName("宋体"); XSSFColor color9 = new XSSFColor(new java.awt.Color(fontColor[0], fontColor[1], fontColor[2])); XSSFColor color10 = new XSSFColor(new java.awt.Color(bgColor[0], bgColor[1], bgColor[2])); if (!(fontColor[0] == 0 && fontColor[1] == 0 && fontColor[2] == 0)) { titleFont.setColor(color9); } titleFont.setBold(true); titleFont.setFontHeightInPoints((short) fontSize); XSSFCellStyle titleStyle = (XSSFCellStyle) createBorderCellStyle(workbook, true); titleStyle.setFont(titleFont); titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); titleStyle.setFillForegroundColor(color10); titleStyle.setAlignment(HorizontalAlignment.CENTER); titleStyle.setVerticalAlignment(VerticalAlignment.CENTER); return titleStyle; }
@Override protected void addBlankCell(JRExporterGridCell gridCell, int colIndex, int rowIndex) { cell = row.createCell(colIndex); FillPatternType mode = backgroundMode; short backcolor = whiteIndex; if (!Boolean.TRUE.equals(sheetInfo.ignoreCellBackground) && gridCell.getCellBackcolor() != null) { mode = FillPatternType.SOLID_FOREGROUND; backcolor = getWorkbookColor(gridCell.getCellBackcolor()).getIndex(); } short forecolor = blackIndex; if (gridCell.getForecolor() != null) { forecolor = getWorkbookColor(gridCell.getForecolor()).getIndex(); } HSSFCellStyle cellStyle = getLoadedCellStyle( mode, backcolor, HorizontalAlignment.LEFT, VerticalAlignment.TOP, (short)0, getLoadedFont(getDefaultFont(), forecolor, null, getLocale()), gridCell, true, true, false, false ); cell.setCellStyle(cellStyle); }
@Override protected void exportRectangle(JRPrintGraphicElement element, JRExporterGridCell gridCell, int colIndex, int rowIndex) { short forecolor = getWorkbookColor(element.getLinePen().getLineColor()).getIndex(); FillPatternType mode = backgroundMode; short backcolor = whiteIndex; if (!Boolean.TRUE.equals(sheetInfo.ignoreCellBackground) && gridCell.getCellBackcolor() != null) { mode = FillPatternType.SOLID_FOREGROUND; backcolor = getWorkbookColor(gridCell.getCellBackcolor()).getIndex(); } HSSFCellStyle cellStyle = getLoadedCellStyle( mode, backcolor, HorizontalAlignment.LEFT, VerticalAlignment.TOP, (short)0, getLoadedFont(getDefaultFont(), forecolor, null, getLocale()), gridCell, isWrapText(element), isCellLocked(element), isCellHidden(element), isShrinkToFit(element) ); createMergeRegion(gridCell, colIndex, rowIndex, cellStyle); cell = row.createCell(colIndex); cell.setCellStyle(cellStyle); }
private VerticalAlignment getVerticalAlignment(TextAlignHolder alignment) { switch (alignment.verticalAlignment) { case BOTTOM: return VerticalAlignment.BOTTOM; case MIDDLE: return VerticalAlignment.CENTER; case JUSTIFIED: return VerticalAlignment.JUSTIFY; case TOP: default: return VerticalAlignment.TOP; } }
protected HSSFCellStyle getLoadedCellStyle( FillPatternType mode, short backcolor, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, short rotation, HSSFFont font, JRExporterGridCell gridCell, boolean isWrapText, boolean isCellLocked, boolean isCellHidden, boolean isShrinkToFit ) { return getLoadedCellStyle( new StyleInfo( mode, backcolor, horizontalAlignment, verticalAlignment, rotation, font, gridCell, isWrapText, isCellLocked, isCellHidden, isShrinkToFit)); }
@Override protected void exportFrame(JRPrintFrame frame, JRExporterGridCell gridCell, int x, int y) { FillPatternType mode = backgroundMode; short backcolor = whiteIndex; if (frame.getModeValue() == ModeEnum.OPAQUE) { mode = FillPatternType.SOLID_FOREGROUND; backcolor = getWorkbookColor(frame.getBackcolor()).getIndex(); } short forecolor = getWorkbookColor(frame.getForecolor()).getIndex(); HSSFCellStyle cellStyle = getLoadedCellStyle( mode, backcolor, HorizontalAlignment.LEFT, VerticalAlignment.TOP, (short)0, getLoadedFont(getDefaultFont(), forecolor, null, getLocale()), gridCell, isWrapText(frame), isCellLocked(frame), isCellHidden(frame), isShrinkToFit(frame) ); createMergeRegion(gridCell, x, y, cellStyle); cell = row.createCell(x); cell.setCellStyle(cellStyle); }
public StyleInfo( FillPatternType mode, short backcolor, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, short rotation, HSSFFont font, BoxStyle box, boolean wrapText, boolean cellLocked, boolean cellHidden, boolean shrinkToFit ) { this.mode = mode; this.backcolor = backcolor; this.horizontalAlignment = horizontalAlignment; this.verticalAlignment = verticalAlignment; this.rotation = rotation; this.font = font; this.box = box; this.lcWrapText = shrinkToFit ? false : wrapText; this.lcCellLocked = cellLocked; this.lcCellHidden = cellHidden; this.lcShrinkToFit = shrinkToFit; hashCode = computeHash(); }
@Override protected void exportRectangle(JRPrintGraphicElement element) throws JRException { String currentColumnName = element.getPropertiesMap().getProperty(JRXlsAbstractMetadataExporter.PROPERTY_COLUMN_NAME); if (currentColumnName != null && currentColumnName.length() > 0) { boolean repeatValue = getPropertiesUtil().getBooleanProperty(element, JRXlsAbstractMetadataExporter.PROPERTY_REPEAT_VALUE, false); setColumnName(currentColumnName); adjustColumnWidth(currentColumnName, element.getWidth(), ((JRXlsExporterNature)nature).getColumnAutoFit(element)); adjustRowHeight(element.getHeight(), ((JRXlsExporterNature)nature).getRowAutoFit(element)); short forecolor = getWorkbookColor(element.getLinePen().getLineColor()).getIndex(); FillPatternType mode = backgroundMode; short backcolor = whiteIndex; if (!Boolean.TRUE.equals(sheetInfo.ignoreCellBackground) && element.getBackcolor() != null) { mode = FillPatternType.SOLID_FOREGROUND; backcolor = getWorkbookColor(element.getBackcolor()).getIndex(); } HSSFCellStyle cellStyle = getLoadedCellStyle( mode, backcolor, HorizontalAlignment.LEFT, VerticalAlignment.TOP, (short)0, getLoadedFont(getDefaultFont(), forecolor, null, getLocale()), new BoxStyle(element), isCellLocked(element), isCellHidden(element), isShrinkToFit(element) ); addBlankElement(cellStyle, repeatValue, currentColumnName); } }
protected HSSFCellStyle getLoadedCellStyle( FillPatternType mode, short backcolor, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, short rotation, HSSFFont font, BoxStyle box, boolean isCellLocked, boolean isCellHidden, boolean isShrinkToFit ) { return getLoadedCellStyle(new StyleInfo(mode, backcolor, horizontalAlignment, verticalAlignment, rotation, font, box, true, isCellLocked, isCellHidden, isShrinkToFit)); }
public static VerticalAlignment vAlignToPoi(VAlign vAlign) { switch (vAlign) { case ALIGN_TOP: return VerticalAlignment.TOP; case ALIGN_MIDDLE: return VerticalAlignment.CENTER; case ALIGN_BOTTOM: return VerticalAlignment.BOTTOM; case ALIGN_JUSTIFY: return VerticalAlignment.JUSTIFY; default: throw new IllegalArgumentException(); } }
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; }
public HSSFCellStyle createHeaderStyle() { HSSFCellStyle style = workbook.createCellStyle(); final HSSFFont font = workbook.createFont(); font.setBold(true); style.setFont(font); style.setBorderBottom(BorderStyle.THIN); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setAlignment(HorizontalAlignment.CENTER); style.setFillForegroundColor(HSSFColor.HSSFColorPredefined.PALE_BLUE.getIndex()); return style; }
public HSSFCellStyle createTitleStyle() { HSSFCellStyle style = workbook.createCellStyle(); final HSSFFont font = workbook.createFont(); font.setBold(true); style.setFont(font); style.setBorderBottom(BorderStyle.THICK); style.setVerticalAlignment(VerticalAlignment.CENTER); return style; }
public HSSFCellStyle createDefaultStyle() { HSSFCellStyle style = workbook.createCellStyle(); HSSFFont font = workbook.createFont(); style.setFont(font); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setAlignment(HorizontalAlignment.CENTER); return style; }
@Test public void testVerticalAlign () { final ExcelStyle e = new ExcelStyle (); assertNull (e.getVerticalAlign ()); CommonsTestHelper.testGetClone (e); for (final VerticalAlignment eAlign : VerticalAlignment.values ()) { assertSame (e, e.setVerticalAlign (eAlign)); assertEquals (eAlign, e.getVerticalAlign ()); CommonsTestHelper.testGetClone (e); } }
private Map<String, CellStyle> createHSSFCellStyles(Workbook wb, int[] contextBgColor, int[] contextFontColor, int contextFontSize, int contextFontAlign, int[] headerBgColor, int[] headerFontColor, int headerFontSize, int headerAlign) { Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); HSSFWorkbook workbook = (HSSFWorkbook) wb; HSSFPalette palette = workbook.getCustomPalette(); palette.setColorAtIndex((short) 11, (byte) contextBgColor[0], (byte) contextBgColor[1], (byte) contextBgColor[2]); palette.setColorAtIndex((short) 12, (byte) contextFontColor[0], (byte) contextFontColor[1], (byte) contextFontColor[2]); palette.setColorAtIndex((short) 13, (byte) headerBgColor[0], (byte) headerBgColor[1], (byte) headerBgColor[2]); palette.setColorAtIndex((short) 14, (byte) headerFontColor[0], (byte) headerFontColor[1], (byte) headerFontColor[2]); HSSFFont headerFont = workbook.createFont(); headerFont.setCharSet(HSSFFont.DEFAULT_CHARSET); headerFont.setFontName("宋体"); headerFont.setColor((short) 14); headerFont.setBold(true); headerFont.setFontHeightInPoints((short) headerFontSize); CellStyle headerStyle = this.createBorderCellStyle(workbook, true); headerStyle.setFont(headerFont); headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); headerStyle.setFillForegroundColor((short) 13); this.setCellStyleAligment(headerStyle, headerAlign); headerStyle.setVerticalAlignment(VerticalAlignment.CENTER); styles.put(GridStyleType.headerStyle.name(), headerStyle); HSSFFont dataFont = workbook.createFont(); dataFont.setColor((short) 12); dataFont.setFontHeightInPoints((short) contextFontSize); dataFont.setCharSet(HSSFFont.DEFAULT_CHARSET); dataFont.setFontName("宋体"); CellStyle dataAlignLeftStyle = this.createBorderCellStyle(workbook, true); dataAlignLeftStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); dataAlignLeftStyle.setFillForegroundColor((short) 11); dataAlignLeftStyle.setFont(dataFont); dataAlignLeftStyle.setVerticalAlignment(VerticalAlignment.CENTER); dataAlignLeftStyle.setWrapText(true); dataAlignLeftStyle.setAlignment(HorizontalAlignment.LEFT); styles.put(GridStyleType.dataAlignLeftStyle.name(), dataAlignLeftStyle); CellStyle dataAlignCenterStyle = this.createBorderCellStyle(workbook, true); dataAlignCenterStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); dataAlignCenterStyle.setFillForegroundColor((short) 11); dataAlignCenterStyle.setFont(dataFont); dataAlignCenterStyle.setVerticalAlignment(VerticalAlignment.CENTER); dataAlignCenterStyle.setWrapText(true); dataAlignCenterStyle.setAlignment(HorizontalAlignment.CENTER); styles.put(GridStyleType.dataAlignCenterStyle.name(), dataAlignCenterStyle); CellStyle dataAlignRightStyle = this.createBorderCellStyle(workbook, true); dataAlignRightStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); dataAlignRightStyle.setFillForegroundColor((short) 11); dataAlignRightStyle.setFont(dataFont); dataAlignRightStyle.setVerticalAlignment(VerticalAlignment.CENTER); dataAlignRightStyle.setWrapText(true); dataAlignRightStyle.setAlignment(HorizontalAlignment.RIGHT); styles.put(GridStyleType.dataAlignRightStyle.name(), dataAlignRightStyle); CellStyle dateStyle = this.createBorderCellStyle(workbook, true); CreationHelper helper = workbook.getCreationHelper(); dateStyle.setDataFormat(helper.createDataFormat().getFormat("m/d/yy h:mm")); dateStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); dateStyle.setFillForegroundColor((short) 11); dateStyle.setFont(dataFont); dateStyle.setVerticalAlignment(VerticalAlignment.CENTER); this.setCellStyleAligment(dateStyle, contextFontAlign); styles.put(GridStyleType.dateStyle.name(), dateStyle); return styles; }
private Map<String, CellStyle> createXSSFCellStyles(Workbook wb, int[] contextBgColor, int[] contextFontColor, int contextFontSize, int contextFontAlign, int[] headerBgColor, int[] headerFontColor, int headerFontSize, int headerAlign) { Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); SXSSFWorkbook workbook = (SXSSFWorkbook) wb; XSSFColor xssfContextBgColor = new XSSFColor(new java.awt.Color(contextBgColor[0], contextBgColor[1], contextBgColor[2])); XSSFColor xssfContextFontColor = new XSSFColor(new java.awt.Color(contextFontColor[0], contextFontColor[1], contextFontColor[2])); XSSFColor xssfHeaderBgColor = new XSSFColor(new java.awt.Color(headerBgColor[0], headerBgColor[1], headerBgColor[2])); XSSFColor xssfHeaderFontColor = new XSSFColor(new java.awt.Color(headerFontColor[0], headerFontColor[1], headerFontColor[2])); XSSFFont headerFont = (XSSFFont) workbook.createFont(); headerFont.setCharSet(HSSFFont.DEFAULT_CHARSET); headerFont.setFontName("宋体"); if (!(headerFontColor[0] == 0 && headerFontColor[1] == 0 && headerFontColor[2] == 0)) { headerFont.setColor(xssfHeaderFontColor); } headerFont.setBold(true); headerFont.setFontHeightInPoints((short) headerFontSize); XSSFCellStyle headerStyle = (XSSFCellStyle) this.createBorderCellStyle(workbook, true); headerStyle.setFont(headerFont); headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); headerStyle.setFillForegroundColor(xssfHeaderBgColor); this.setCellStyleAligment(headerStyle, headerAlign); headerStyle.setVerticalAlignment(VerticalAlignment.CENTER); styles.put(GridStyleType.headerStyle.name(), headerStyle); XSSFFont dataFont = (XSSFFont) workbook.createFont(); if (!(contextFontColor[0] == 0 && contextFontColor[1] == 0 && contextFontColor[2] == 0)) { dataFont.setColor(xssfContextFontColor); } dataFont.setFontHeightInPoints((short) contextFontSize); dataFont.setCharSet(HSSFFont.DEFAULT_CHARSET); dataFont.setFontName("宋体"); XSSFCellStyle dataAlignLeftStyle = (XSSFCellStyle) this.createBorderCellStyle(workbook, true); dataAlignLeftStyle.setFont(dataFont); dataAlignLeftStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); dataAlignLeftStyle.setFillForegroundColor(xssfContextBgColor); dataAlignLeftStyle.setVerticalAlignment(VerticalAlignment.CENTER); dataAlignLeftStyle.setWrapText(true); dataAlignLeftStyle.setAlignment(HorizontalAlignment.LEFT); styles.put(GridStyleType.dataAlignLeftStyle.name(), dataAlignLeftStyle); XSSFCellStyle dataAlignCenterStyle = (XSSFCellStyle) this.createBorderCellStyle(workbook, true); dataAlignCenterStyle.setFont(dataFont); dataAlignCenterStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); dataAlignCenterStyle.setFillForegroundColor(xssfContextBgColor); dataAlignCenterStyle.setVerticalAlignment(VerticalAlignment.CENTER); dataAlignCenterStyle.setWrapText(true); dataAlignCenterStyle.setAlignment(HorizontalAlignment.CENTER); styles.put(GridStyleType.dataAlignCenterStyle.name(), dataAlignCenterStyle); XSSFCellStyle dataAlignRightStyle = (XSSFCellStyle) this.createBorderCellStyle(workbook, true); dataAlignRightStyle.setFont(dataFont); dataAlignRightStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); dataAlignRightStyle.setFillForegroundColor(xssfContextBgColor); dataAlignRightStyle.setVerticalAlignment(VerticalAlignment.CENTER); dataAlignRightStyle.setWrapText(true); dataAlignRightStyle.setAlignment(HorizontalAlignment.RIGHT); styles.put(GridStyleType.dataAlignRightStyle.name(), dataAlignRightStyle); XSSFCellStyle dateStyle = (XSSFCellStyle) this.createBorderCellStyle(workbook, true); CreationHelper helper = workbook.getCreationHelper(); dateStyle.setDataFormat(helper.createDataFormat().getFormat("m/d/yy h:mm")); dateStyle.setFont(dataFont); dateStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); dateStyle.setFillForegroundColor(xssfContextBgColor); dateStyle.setVerticalAlignment(VerticalAlignment.CENTER); this.setCellStyleAligment(dateStyle, contextFontAlign); styles.put(GridStyleType.dateStyle.name(), dateStyle); return styles; }
@Override protected void exportLine(JRPrintLine line, JRExporterGridCell gridCell, int colIndex, int rowIndex) { short forecolor = getWorkbookColor(line.getLinePen().getLineColor()).getIndex(); int side = BoxStyle.TOP; float ratio = line.getWidth() / line.getHeight(); if (ratio > 1) { if (line.getDirectionValue() == LineDirectionEnum.TOP_DOWN) { side = BoxStyle.TOP; } else { side = BoxStyle.BOTTOM; } } else { if (line.getDirectionValue() == LineDirectionEnum.TOP_DOWN) { side = BoxStyle.LEFT; } else { side = BoxStyle.RIGHT; } } BoxStyle boxStyle = new BoxStyle(side, line.getLinePen()); FillPatternType mode = backgroundMode; short backcolor = whiteIndex; if (!Boolean.TRUE.equals(sheetInfo.ignoreCellBackground) && gridCell.getCellBackcolor() != null) { mode = FillPatternType.SOLID_FOREGROUND; backcolor = getWorkbookColor(gridCell.getCellBackcolor()).getIndex(); } HSSFCellStyle cellStyle = getLoadedCellStyle( mode, backcolor, HorizontalAlignment.LEFT, VerticalAlignment.TOP, (short)0, getLoadedFont(getDefaultFont(), forecolor, null, getLocale()), boxStyle, false, isCellLocked(line), isCellHidden(line), isShrinkToFit(line) ); createMergeRegion(gridCell, colIndex, rowIndex, cellStyle); cell = row.createCell(colIndex); cell.setCellStyle(cellStyle); }
@Override public void exportText(JRPrintText textElement, JRExporterGridCell gridCell, int colIndex, int rowIndex) throws JRException { JRStyledText styledText = getStyledText(textElement); if (styledText == null) { return; } short forecolor = getWorkbookColor(textElement.getForecolor()).getIndex(); TextAlignHolder textAlignHolder = getTextAlignHolder(textElement); HorizontalAlignment horizontalAlignment = getHorizontalAlignment(textAlignHolder); VerticalAlignment verticalAlignment = getVerticalAlignment(textAlignHolder); short rotation = getRotation(textAlignHolder); FillPatternType mode = backgroundMode; short backcolor = whiteIndex; if (!Boolean.TRUE.equals(sheetInfo.ignoreCellBackground) && gridCell.getCellBackcolor() != null) { mode = FillPatternType.SOLID_FOREGROUND; backcolor = getWorkbookColor(gridCell.getCellBackcolor()).getIndex(); } StyleInfo baseStyle = isIgnoreTextFormatting(textElement) ? new StyleInfo( mode, whiteIndex, horizontalAlignment, verticalAlignment, (short)0, null, (JRExporterGridCell)null, isWrapText(textElement) || Boolean.TRUE.equals(((JRXlsExporterNature)nature).getColumnAutoFit(textElement)), isCellLocked(textElement), isCellHidden(textElement), isShrinkToFit(textElement) ) : new StyleInfo( mode, backcolor, horizontalAlignment, verticalAlignment, rotation, getLoadedFont(textElement, forecolor, null, getTextLocale(textElement)), gridCell, isWrapText(textElement) || Boolean.TRUE.equals(((JRXlsExporterNature)nature).getColumnAutoFit(textElement)), isCellLocked(textElement), isCellHidden(textElement), isShrinkToFit(textElement) ); createTextCell(textElement, gridCell, colIndex, rowIndex, styledText, baseStyle, forecolor); }
@Override protected void exportLine(JRPrintLine line) throws JRException { String currentColumnName = line.getPropertiesMap().getProperty(JRXlsAbstractMetadataExporter.PROPERTY_COLUMN_NAME); if (currentColumnName != null && currentColumnName.length() > 0) { boolean repeatValue = getPropertiesUtil().getBooleanProperty(line, JRXlsAbstractMetadataExporter.PROPERTY_REPEAT_VALUE, false); setColumnName(currentColumnName); adjustColumnWidth(currentColumnName, line.getWidth(), ((JRXlsExporterNature)nature).getColumnAutoFit(line)); adjustRowHeight(line.getHeight(), ((JRXlsExporterNature)nature).getRowAutoFit(line)); short forecolor = getWorkbookColor(line.getLinePen().getLineColor()).getIndex(); int side = BoxStyle.TOP; float ratio = line.getWidth() / line.getHeight(); if (ratio > 1) { if (line.getDirectionValue() == LineDirectionEnum.TOP_DOWN) { side = BoxStyle.TOP; } else { side = BoxStyle.BOTTOM; } } else { if (line.getDirectionValue() == LineDirectionEnum.TOP_DOWN) { side = BoxStyle.LEFT; } else { side = BoxStyle.RIGHT; } } BoxStyle boxStyle = new BoxStyle(side, line.getLinePen()); FillPatternType mode = backgroundMode; short backcolor = whiteIndex; if (!Boolean.TRUE.equals(sheetInfo.ignoreCellBackground) && line.getBackcolor() != null) { mode = FillPatternType.SOLID_FOREGROUND; backcolor = getWorkbookColor(line.getBackcolor()).getIndex(); } HSSFCellStyle cellStyle = getLoadedCellStyle( mode, backcolor, HorizontalAlignment.LEFT, VerticalAlignment.TOP, (short)0, getLoadedFont(getDefaultFont(), forecolor, null, getLocale()), boxStyle, isCellLocked(line), isCellHidden(line), isShrinkToFit(line) ); addBlankElement(cellStyle, repeatValue, currentColumnName); } }
private int createPdcaItem(XSSFWorkbook wb, XSSFSheet sh, int row, XSSFCellStyle cellNormalStyle, List<PdcaItemVO> items, PdcaAuditVO audit) throws Exception { XSSFColor fnColor = new XSSFColor( SimpleUtils.getColorRGB4POIColor("#000000") ); XSSFColor bgLabelColor = new XSSFColor( SimpleUtils.getColorRGB4POIColor("#F2F2F2") ); XSSFCellStyle cellLabelStyle = wb.createCellStyle(); cellLabelStyle.setFillForegroundColor( bgLabelColor ); cellLabelStyle.setFillPattern( FillPatternType.SOLID_FOREGROUND ); XSSFFont cellLabelFont = wb.createFont(); cellLabelFont.setBold(true); cellLabelFont.setColor(fnColor); cellLabelStyle.setFont(cellLabelFont); cellLabelStyle.setBorderBottom(BorderStyle.THIN); cellLabelStyle.setBorderTop(BorderStyle.THIN); cellLabelStyle.setBorderRight(BorderStyle.THIN); cellLabelStyle.setBorderLeft(BorderStyle.THIN); cellLabelStyle.setVerticalAlignment(VerticalAlignment.CENTER); cellLabelStyle.setAlignment(HorizontalAlignment.CENTER); cellLabelStyle.setWrapText(true); Map<String, String> pdcaTypeMap = PdcaType.getDataMap(false); for (PdcaItemVO item : items) { Row labelRow = sh.createRow(row); Cell labelCell_6_1 = labelRow.createCell(0); labelCell_6_1.setCellValue( pdcaTypeMap.get(item.getType()) ); labelCell_6_1.setCellStyle(cellLabelStyle); Cell labelCell_6_2 = labelRow.createCell(1); labelCell_6_2.setCellValue( item.getTitle() + ( !StringUtils.isBlank(item.getDescription()) ? "\n\n" + item.getDescription() : "" ) ); labelCell_6_2.setCellStyle(cellNormalStyle); Cell labelCell_6_3 = labelRow.createCell(2); labelCell_6_3.setCellValue( item.getEmployeeAppendNames() ); labelCell_6_3.setCellStyle(cellNormalStyle); Cell labelCell_6_4 = labelRow.createCell(3); labelCell_6_4.setCellValue( item.getStartDateDisplayValue() + " ~ " + item.getEndDateDisplayValue() ); labelCell_6_4.setCellStyle(cellNormalStyle); Cell labelCell_6_5 = labelRow.createCell(4); labelCell_6_5.setCellValue( (audit != null ? audit.getEmpId() : " ") ); labelCell_6_5.setCellStyle(cellNormalStyle); Cell labelCell_6_6 = labelRow.createCell(5); labelCell_6_6.setCellValue( (audit != null ? audit.getConfirmDateDisplayValue() : " ") ); labelCell_6_6.setCellStyle(cellNormalStyle); row++; } return row; }
private void createFoot(XSSFWorkbook wb, XSSFSheet sh, int row, VisionVO vision, Context context) throws Exception { Row footRow=sh.createRow(row); Row footRowB=sh.createRow(row+1); XSSFCellStyle cellStyle=wb.createCellStyle(); cellStyle.setFillForegroundColor( new XSSFColor(SimpleUtils.getColorRGB4POIColor("#FFFFFF")) ); cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); cellStyle.setBorderBottom(BorderStyle.THIN); cellStyle.setBorderTop(BorderStyle.THIN); cellStyle.setBorderRight(BorderStyle.THIN); cellStyle.setBorderLeft(BorderStyle.THIN); XSSFFont cellFont=wb.createFont(); cellFont.setBold(true); cellStyle.setFont(cellFont); cellStyle.setWrapText(true); Cell footCell1 = footRow.createCell(0); footCell1.setCellValue("assess:"); footCell1.setCellStyle(cellStyle); Cell footCell1B = footRowB.createCell(0); footCell1B.setCellValue("assess:"); footCell1B.setCellStyle(cellStyle); sh.addMergedRegion(new CellRangeAddress(row, row+1, 0, 0)); Cell footCell2 = footRow.createCell(1); footCell2.setCellValue( BscReportPropertyUtils.getPersonalReportClassLevel() ); footCell2.setCellStyle(cellStyle); Cell footCell3 = footRow.createCell(2); footCell3.setCellValue( BscReportPropertyUtils.getPersonalReportClassLevel() ); footCell3.setCellStyle(cellStyle); Cell footCell4 = footRow.createCell(3); footCell4.setCellValue( BscReportPropertyUtils.getPersonalReportClassLevel() ); footCell4.setCellStyle(cellStyle); Cell footCell2B = footRowB.createCell(1); footCell2B.setCellValue( BscReportPropertyUtils.getPersonalReportClassLevel() ); footCell2B.setCellStyle(cellStyle); Cell footCell3B = footRowB.createCell(2); footCell3B.setCellValue( BscReportPropertyUtils.getPersonalReportClassLevel() ); footCell3B.setCellStyle(cellStyle); Cell footCell4B = footRowB.createCell(3); footCell4B.setCellValue( BscReportPropertyUtils.getPersonalReportClassLevel() ); footCell4B.setCellStyle(cellStyle); sh.addMergedRegion(new CellRangeAddress(row, row+1, 1, 3)); Cell footCell5 = footRow.createCell(4); footCell5.setCellValue("Total"); footCell5.setCellStyle(cellStyle); float total = 0.0f; if ( context.get("total")!=null && context.get("total") instanceof Float ) { total = (Float)context.get("total"); } Cell footCell6 = footRow.createCell(5); footCell6.setCellValue( BscReportSupportUtils.parse2(total) ); footCell6.setCellStyle(cellStyle); Cell footCell5b = footRowB.createCell(4); footCell5b.setCellValue("Class"); footCell5b.setCellStyle(cellStyle); Cell footCell6b = footRowB.createCell(5); footCell6b.setCellValue( "" ); footCell6b.setCellStyle(cellStyle); }
@Nullable public VerticalAlignment getVerticalAlign () { return m_eVAlign; }
@Nonnull public ExcelStyle setVerticalAlign (@Nullable final VerticalAlignment eVAlign) { m_eVAlign = eVAlign; return this; }