/** * Returns the default data cell 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 defaultDataCellStyle(final Workbook wb) { CellStyle style; style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); style.setWrapText(true); style.setBorderRight(BorderStyle.THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(BorderStyle.THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(BorderStyle.THIN); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderBottom(BorderStyle.THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); style.setDataFormat(doubleDataFormat); return style; }
/** * @param wb * @param color * @param foreGround * @return */ public static XSSFCellStyle createBackgroundColorXSSFCellStyle(XSSFWorkbook wb,XSSFColor color,short foreGround){ String message="XSSFWorkbook must not be null!"; Objects.requireNonNull(wb, () -> message); XSSFCellStyle cellStyle=wb.createCellStyle(); cellStyle.setWrapText(true); cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); cellStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER); cellStyle.setBorderBottom(BorderStyle.THIN); cellStyle.setBorderLeft(BorderStyle.THIN); cellStyle.setBorderTop(BorderStyle.THIN); cellStyle.setBorderRight(BorderStyle.THIN); cellStyle.setFillForegroundColor(color); cellStyle.setFillPattern(foreGround); return cellStyle; }
public void setPen(JRPen pen) { if ( borderStyle[TOP] == BorderStyle.NONE && borderStyle[LEFT] == BorderStyle.NONE && borderStyle[BOTTOM] == BorderStyle.NONE && borderStyle[RIGHT] == BorderStyle.NONE ) { BorderStyle style = JRXlsExporter.getBorderStyle(pen); short colour = JRXlsExporter.this.getWorkbookColor(pen.getLineColor()).getIndex(); borderStyle[TOP] = style; borderStyle[BOTTOM] = style; borderStyle[LEFT] = style; borderStyle[RIGHT] = style; borderColour[TOP] = colour; borderColour[BOTTOM] = colour; borderColour[LEFT] = colour; borderColour[RIGHT] = colour; } hash = computeHash(); }
public void setPen(JRPen pen) { if ( borderStyle[TOP] == BorderStyle.NONE && borderStyle[LEFT] == BorderStyle.NONE && borderStyle[BOTTOM] == BorderStyle.NONE && borderStyle[RIGHT] == BorderStyle.NONE ) { BorderStyle style = JRXlsMetadataExporter.getBorderStyle(pen); short colour = JRXlsMetadataExporter.this.getWorkbookColor(pen.getLineColor()).getIndex(); borderStyle[TOP] = style; borderStyle[BOTTOM] = style; borderStyle[LEFT] = style; borderStyle[RIGHT] = style; borderColour[TOP] = colour; borderColour[BOTTOM] = colour; borderColour[LEFT] = colour; borderColour[RIGHT] = colour; } hash = computeHash(); }
@Override public void startExport(List<? extends IExportColumn<?>> columnList) throws Exception { if(m_started) throw new IllegalArgumentException("The writer was already started"); m_started = true; m_columnList = columnList; Workbook wb = m_workbook = createWorkbook(); Font defaultFont = wb.createFont(); defaultFont.setFontHeightInPoints((short) 10); defaultFont.setFontName("Arial"); CellStyle dcs = m_defaultCellStyle = wb.createCellStyle(); dcs.setFont(defaultFont); // FIXME Date format must be locale dependent? CellStyle dates = m_dateStyle = wb.createCellStyle(); dates.setDataFormat(wb.createDataFormat().getFormat("d-m-yyyy")); dates.setFont(defaultFont); CellStyle curs = m_currencyStyle = wb.createCellStyle(); curs.setDataFormat(wb.createDataFormat().getFormat("#,##0.00")); curs.setFont(defaultFont); CellStyle nums = m_numberStyle = wb.createCellStyle(); nums.setDataFormat(wb.createDataFormat().getFormat("#0")); nums.setFont(defaultFont); Font headerFont = wb.createFont(); headerFont.setFontHeightInPoints((short) 10); headerFont.setColor((short) 0xc); headerFont.setBold(true); headerFont.setFontName("Arial"); CellStyle hds = m_headerStyle = wb.createCellStyle(); hds.setBorderBottom(BorderStyle.THIN); hds.setDataFormat(HSSFDataFormat.getBuiltinFormat("text")); hds.setFont(headerFont); createNewSheet(columnList); }
public static HSSFCellStyle createCellStyleForColumnHeading(HSSFWorkbook workBook) { HSSFCellStyle cellStyle = workBook.createCellStyle(); HSSFFont fontObj = workBook.createFont(); cellStyle.setBorderBottom(BorderStyle.THIN); cellStyle.setBorderTop(BorderStyle.THIN); cellStyle.setBorderLeft(BorderStyle.THIN); cellStyle.setBorderRight(BorderStyle.THIN); cellStyle.setWrapText(true); cellStyle.setAlignment(HorizontalAlignment.CENTER); cellStyle.setFillBackgroundColor(Short.valueOf("22").shortValue()); cellStyle.setFillPattern(FillPatternType.BIG_SPOTS); cellStyle.setFillForegroundColor(Short.valueOf("22").shortValue()); cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); fontObj.setFontName("Calibri"); fontObj.setFontHeightInPoints(Short.valueOf("12").shortValue()); fontObj.setBold(true); fontObj.setColor(Short.valueOf("8").shortValue()); cellStyle.setFont(fontObj); return cellStyle; }
/** * 普通单元格样式 * * @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; }
@Test public void testBorder () { final ExcelStyle e = new ExcelStyle (); assertNull (e.getBorderTop ()); assertNull (e.getBorderRight ()); assertNull (e.getBorderBottom ()); assertNull (e.getBorderLeft ()); CommonsTestHelper.testGetClone (e); for (final BorderStyle eBorder : BorderStyle.values ()) { assertSame (e, e.setBorder (eBorder)); assertEquals (eBorder, e.getBorderTop ()); assertEquals (eBorder, e.getBorderRight ()); assertEquals (eBorder, e.getBorderBottom ()); assertEquals (eBorder, e.getBorderLeft ()); CommonsTestHelper.testGetClone (e); } }
public static XSSFCellStyle createCenterXSSFCellStyle(XSSFWorkbook wb){ String message="XSSFWorkbook must not be null!"; Objects.requireNonNull(wb, () -> message); XSSFCellStyle cellStyle=wb.createCellStyle(); cellStyle.setWrapText(true); cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); cellStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER); cellStyle.setBorderBottom(BorderStyle.THIN); cellStyle.setBorderLeft(BorderStyle.THIN); cellStyle.setBorderTop(BorderStyle.THIN); cellStyle.setBorderRight(BorderStyle.THIN); return cellStyle; }
@Override public void initialize(Workbook workbook) { this.borderStyle = workbook.createCellStyle(); this.borderStyle.setBorderBottom(BorderStyle.THIN); this.borderStyle.setBorderTop(BorderStyle.THIN); this.borderStyle.setBorderRight(BorderStyle.THIN); this.borderStyle.setBorderLeft(BorderStyle.THIN); }
private BorderStyle getBorderStyle(Border border){ if(border.getStyle().equals(com.bstek.ureport.definition.BorderStyle.solid)){ return BorderStyle.THIN; }else if(border.getStyle().equals(com.bstek.ureport.definition.BorderStyle.dashed)){ return BorderStyle.DASHED; }else if(border.getStyle().equals(com.bstek.ureport.definition.BorderStyle.doublesolid)){ return BorderStyle.DOUBLE; } return null; }
public CellStyle createBorderCellStyle(Workbook workbook, boolean showBorder) { CellStyle style = workbook.createCellStyle(); if (showBorder) { 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; }
public static XSSFCellStyle createTitleXSSFCellStyle(XSSFWorkbook wb){ String message="XSSFWorkbook must not be null!"; Objects.requireNonNull(wb, () -> message); XSSFCellStyle cellStyle=wb.createCellStyle(); cellStyle.setWrapText(true); cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); cellStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER); cellStyle.setBorderBottom(BorderStyle.THIN); cellStyle.setBorderLeft(BorderStyle.THIN); cellStyle.setBorderTop(BorderStyle.THIN); cellStyle.setBorderRight(BorderStyle.THIN); cellStyle.setFillForegroundColor(new XSSFColor( new Color(75, 172, 198))); cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); return cellStyle; }
/** * Sets the borders. * * @param headerCellStyle * the header cell style * @param left * the left * @param right * the right * @param top * the top * @param bottom * the bottom * @param color * the color * @return the XSSF cell style */ public static XSSFCellStyle setBorders(final XSSFCellStyle headerCellStyle, final Boolean left, final Boolean right, final Boolean top, final Boolean bottom, final Color color) { if (bottom) { headerCellStyle.setBorderBottom(BorderStyle.THIN); headerCellStyle.setBorderColor(BorderSide.BOTTOM, new XSSFColor(color)); } if (top) { headerCellStyle.setBorderTop(BorderStyle.THIN); headerCellStyle.setBorderColor(BorderSide.TOP, new XSSFColor(color)); } if (left) { headerCellStyle.setBorderLeft(BorderStyle.THIN); headerCellStyle.setBorderColor(BorderSide.LEFT, new XSSFColor(color)); } if (right) { headerCellStyle.setBorderRight(BorderStyle.THIN); headerCellStyle.setBorderColor(BorderSide.RIGHT, new XSSFColor(color)); } return headerCellStyle; }
/** * */ protected static BorderStyle getBorderStyle(JRPen pen) { float lineWidth = pen.getLineWidth().floatValue(); if (lineWidth > 0f) { switch (pen.getLineStyleValue()) { case DOUBLE : { return BorderStyle.DOUBLE; } case DOTTED : { return BorderStyle.DOTTED; } case DASHED : { if (lineWidth >= 1f) { return BorderStyle.MEDIUM_DASHED; } return BorderStyle.DASHED; } case SOLID : default : { if (lineWidth >= 2f) { return BorderStyle.THICK; } else if (lineWidth >= 1f) { return BorderStyle.MEDIUM; } else if (lineWidth >= 0.5f) { return BorderStyle.THIN; } return BorderStyle.HAIR; } } } return BorderStyle.NONE; }
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; }
@Test public void testBasic () { final ExcelStyle e = new ExcelStyle (); CommonsTestHelper.testDefaultImplementationWithEqualContentObject (e, new ExcelStyle ()); e.setBorder (BorderStyle.DASH_DOT); CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (e, new ExcelStyle ()); CommonsTestHelper.testDefaultImplementationWithEqualContentObject (e, new ExcelStyle ().setBorder (BorderStyle.DASH_DOT)); }
@Override public void applyBorderStyle(Workbook workbook, CellStyle style, BorderSide side, CSSValue colour, CSSValue borderStyle, CSSValue width) { if( ( colour != null ) || ( borderStyle != null ) || ( width != null ) ) { String colourString = colour == null ? "rgb(0,0,0)" : colour.getCssText(); String borderStyleString = borderStyle == null ? "solid" : borderStyle.getCssText(); String widthString = width == null ? "medium" : width.getCssText(); if( style instanceof XSSFCellStyle ) { XSSFCellStyle xStyle = (XSSFCellStyle)style; BorderStyle xBorderStyle = poiBorderStyleFromBirt(borderStyleString, widthString); XSSFColor xBorderColour = getXColour(colourString); if(xBorderStyle != BorderStyle.NONE) { switch( side ) { case TOP: xStyle.setBorderTop(xBorderStyle); xStyle.setTopBorderColor(xBorderColour); // log.debug( "Top border: " + xStyle.getBorderTop() + " / " + xStyle.getTopBorderXSSFColor().getARGBHex() ); break; case LEFT: xStyle.setBorderLeft(xBorderStyle); xStyle.setLeftBorderColor(xBorderColour); // log.debug( "Left border: " + xStyle.getBorderLeft() + " / " + xStyle.getLeftBorderXSSFColor().getARGBHex() ); break; case RIGHT: xStyle.setBorderRight(xBorderStyle); xStyle.setRightBorderColor(xBorderColour); // log.debug( "Right border: " + xStyle.getBorderRight() + " / " + xStyle.getRightBorderXSSFColor().getARGBHex() ); break; case BOTTOM: xStyle.setBorderBottom(xBorderStyle); xStyle.setBottomBorderColor(xBorderColour); // log.debug( "Bottom border: " + xStyle.getBorderBottom() + " / " + xStyle.getBottomBorderXSSFColor().getARGBHex() ); break; } } } } }
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; }
@SuppressWarnings("unchecked") private void putTables(XSSFWorkbook wb, XSSFSheet sh, Context context) throws Exception { XSSFCellStyle cellHeadStyle = wb.createCellStyle(); cellHeadStyle.setFillForegroundColor( new XSSFColor( SimpleUtils.getColorRGB4POIColor( "#f5f5f5" ) ) ); cellHeadStyle.setFillPattern( FillPatternType.SOLID_FOREGROUND ); cellHeadStyle.setBorderBottom( BorderStyle.THIN ); cellHeadStyle.setBorderTop( BorderStyle.THIN ); cellHeadStyle.setBorderRight( BorderStyle.THIN ); cellHeadStyle.setBorderLeft( BorderStyle.THIN ); XSSFFont cellHeadFont = wb.createFont(); cellHeadFont.setBold(true); cellHeadStyle.setFont( cellHeadFont ); sh.setColumnWidth(0, 12000); int row = 0; Row nowRow = sh.createRow(row); Cell cell1 = nowRow.createCell(0); cell1.setCellStyle(cellHeadStyle); cell1.setCellValue( "KPI" ); Cell cell2 = nowRow.createCell(1); cell2.setCellStyle(cellHeadStyle); cell2.setCellValue( "Maximum" ); Cell cell3 = nowRow.createCell(2); cell3.setCellStyle(cellHeadStyle); cell3.setCellValue( "Target" ); Cell cell4 = nowRow.createCell(3); cell4.setCellStyle(cellHeadStyle); cell4.setCellValue( "Minimum" ); Cell cell5 = nowRow.createCell(4); cell5.setCellStyle(cellHeadStyle); cell5.setCellValue( "Current score" ); Cell cell6 = nowRow.createCell(5); cell6.setCellStyle(cellHeadStyle); cell6.setCellValue( "Previous score" ); Cell cell7 = nowRow.createCell(6); cell7.setCellStyle(cellHeadStyle); cell7.setCellValue( "Change(%)" ); row++; List<PeriodTrendsData<KpiVO>> periodDatas = (List<PeriodTrendsData<KpiVO>>)context.get("periodDatas"); for (PeriodTrendsData<KpiVO> periodData : periodDatas) { nowRow = sh.createRow(row); cell1 = nowRow.createCell(0); cell1.setCellValue( periodData.getCurrent().getName() ); cell2 = nowRow.createCell(1); cell2.setCellValue( periodData.getCurrent().getMax() ); cell3 = nowRow.createCell(2); cell3.setCellValue( periodData.getCurrent().getTarget() ); cell4 = nowRow.createCell(3); cell4.setCellValue( periodData.getCurrent().getMin() ); cell5 = nowRow.createCell(4); cell5.setCellValue( BscReportSupportUtils.parse2( periodData.getCurrent().getScore() ) ); cell6 = nowRow.createCell(5); cell6.setCellValue( BscReportSupportUtils.parse2( periodData.getPrevious().getScore() ) ); cell7 = nowRow.createCell(6); cell7.setCellValue( BscReportSupportUtils.parse2( periodData.getChange() ) ); row++; } nowRow = sh.createRow(row); cell1 = nowRow.createCell(0); cell1.setCellValue( "Current period: " + (String)context.get("currentPeriodDateRange") + " , Previous period: " + (String)context.get("previousPeriodDateRange") ); }
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); }
private Workbook getAsWorkbook(List<List<Object>> spreadsheetData) { Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet(); CellStyle headerCs = wb.createCellStyle(); Iterator<List<Object>> dataIter = spreadsheetData.iterator(); // Set the header style headerCs.setBorderBottom(BorderStyle.THICK); headerCs.setFillBackgroundColor(IndexedColors.BLUE_GREY.getIndex()); // Set the font CellStyle cellStyle = null; String fontName = ServerConfigurationService.getString("spreadsheet.font"); if (fontName != null) { Font font = wb.createFont(); font.setFontName(fontName); headerCs.setFont(font); cellStyle = wb.createCellStyle(); cellStyle.setFont(font); } // By convention, the first list in the list contains column headers. Row headerRow = sheet.createRow((short)0); List<Object> headerList = dataIter.next(); for (short i = 0; i < headerList.size(); i++) { Cell headerCell = createCell(headerRow, i); headerCell.setCellValue((String)headerList.get(i)); headerCell.setCellStyle(headerCs); sheet.autoSizeColumn(i); } short rowPos = 1; while (dataIter.hasNext()) { List<Object> rowData = dataIter.next(); Row row = sheet.createRow(rowPos++); for (short i = 0; i < rowData.size(); i++) { Cell cell = createCell(row, i); Object data = rowData.get(i); if (data != null) { if (data instanceof Double) { cell.setCellValue(((Double)data).doubleValue()); } else { cell.setCellValue(data.toString()); } if (cellStyle != null) { cell.setCellStyle(cellStyle); } } } } return wb; }
private Workbook getAsWorkbook(List<List<Object>> spreadsheetData) { Workbook wb = new SXSSFWorkbook(); Sheet sheet = wb.createSheet(); CellStyle headerCs = wb.createCellStyle(); Iterator<List<Object>> dataIter = spreadsheetData.iterator(); // Set the header style headerCs.setBorderBottom(BorderStyle.THICK); headerCs.setFillBackgroundColor(IndexedColors.BLUE_GREY.getIndex()); // Set the font CellStyle cellStyle = null; String fontName = ServerConfigurationService.getString("spreadsheet.font"); if (fontName != null) { Font font = wb.createFont(); font.setFontName(fontName); headerCs.setFont(font); cellStyle = wb.createCellStyle(); cellStyle.setFont(font); } // By convention, the first list in the list contains column headers. Row headerRow = sheet.createRow((short)0); List<Object> headerList = dataIter.next(); for (short i = 0; i < headerList.size(); i++) { Cell headerCell = createCell(headerRow, i); headerCell.setCellValue((String)headerList.get(i)); headerCell.setCellStyle(headerCs); //TODO //sheet.autoSizeColumn(i); } short rowPos = 1; while (dataIter.hasNext()) { List<Object> rowData = dataIter.next(); Row row = sheet.createRow(rowPos++); for (short i = 0; i < rowData.size(); i++) { Cell cell = createCell(row, i); Object data = rowData.get(i); if (data != null) { if (data instanceof Double) { cell.setCellValue(((Double)data).doubleValue()); } else { cell.setCellValue(data.toString()); } if (cellStyle != null) { cell.setCellStyle(cellStyle); } } } } return wb; }
@Nullable public BorderStyle getBorderTop () { return m_eBorderTop; }
@Nonnull public ExcelStyle setBorderTop (@Nullable final BorderStyle eBorder) { m_eBorderTop = eBorder; return this; }
@Nullable public BorderStyle getBorderRight () { return m_eBorderRight; }
@Nonnull public ExcelStyle setBorderRight (@Nullable final BorderStyle eBorder) { m_eBorderRight = eBorder; return this; }
@Nullable public BorderStyle getBorderBottom () { return m_eBorderBottom; }
@Nonnull public ExcelStyle setBorderBottom (@Nullable final BorderStyle eBorder) { m_eBorderBottom = eBorder; return this; }
@Nullable public BorderStyle getBorderLeft () { return m_eBorderLeft; }
@Nonnull public ExcelStyle setBorderLeft (@Nullable final BorderStyle eBorder) { m_eBorderLeft = eBorder; return this; }