List of usage examples for org.apache.poi.xssf.usermodel XSSFSheet addMergedRegion
@Override public int addMergedRegion(CellRangeAddress region)
From source file:com.netsteadfast.greenstep.bsc.command.PersonalReportExcelCommand.java
License:Apache License
private int createHead(XSSFWorkbook wb, XSSFSheet sh, int row, VisionVO vision, Context context) throws Exception { String dateType = (String) context.get("dateType"); String year = (String) context.get("startYearDate"); String empId = (String) context.get("empId"); String account = (String) context.get("account"); String fullName = ""; String jobTitle = ""; String departmentName = ""; String dateTypeName = "Year"; if ("1".equals(dateType)) { dateTypeName = "In the first half"; }//ww w . j ava 2 s . c o m if ("2".equals(dateType)) { dateTypeName = "In the second half"; } EmployeeVO employee = new EmployeeVO(); employee.setEmpId(empId); employee.setAccount(account); DefaultResult<EmployeeVO> result = this.employeeService.findByUK(employee); if (result.getValue() != null) { fullName = result.getValue().getEmpId() + " - " + result.getValue().getFullName(); jobTitle = result.getValue().getEmpId() + " - " + result.getValue().getFullName(); List<String> appendIds = this.organizationService .findForAppendOrganizationOids(result.getValue().getEmpId()); List<String> appendNames = this.organizationService.findForAppendNames(appendIds); StringBuilder sb = new StringBuilder(); for (int i = 0; appendNames != null && i < appendNames.size(); i++) { sb.append(appendNames.get(i)).append(Constants.ID_DELIMITER); } departmentName = sb.toString(); } Row headRow = sh.createRow(row); headRow.setHeight((short) 700); XSSFColor bgColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor("#F2F2F2")); XSSFColor fnColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor("#000000")); XSSFCellStyle cellHeadStyle = wb.createCellStyle(); cellHeadStyle.setFillForegroundColor(bgColor); cellHeadStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); XSSFFont cellHeadFont = wb.createFont(); cellHeadFont.setBold(true); cellHeadFont.setColor(fnColor); cellHeadStyle.setFont(cellHeadFont); cellHeadStyle.setBorderBottom(BorderStyle.THIN); cellHeadStyle.setBorderTop(BorderStyle.THIN); cellHeadStyle.setBorderRight(BorderStyle.THIN); cellHeadStyle.setBorderLeft(BorderStyle.THIN); cellHeadStyle.setVerticalAlignment(VerticalAlignment.CENTER); cellHeadStyle.setAlignment(HorizontalAlignment.CENTER); cellHeadStyle.setWrapText(true); int cols = 6; for (int i = 0; i < cols; i++) { sh.setColumnWidth(i, 6000); Cell headCell1 = headRow.createCell(i); headCell1.setCellValue("Personal Balance SourceCard"); headCell1.setCellStyle(cellHeadStyle); } sh.addMergedRegion(new CellRangeAddress(row, row, 0, cols - 1)); row++; headRow = sh.createRow(row); for (int i = 0; i < cols; i++) { sh.setColumnWidth(i, 6000); Cell headCell1 = headRow.createCell(i); headCell1.setCellValue(vision.getTitle()); headCell1.setCellStyle(cellHeadStyle); } sh.addMergedRegion(new CellRangeAddress(row, row, 0, cols - 1)); row++; headRow = sh.createRow(row); headRow.setHeight((short) 700); Cell titleCell1 = headRow.createCell(0); titleCell1.setCellValue("Job Title"); titleCell1.setCellStyle(cellHeadStyle); Cell titleCell2 = headRow.createCell(1); titleCell2.setCellValue(jobTitle); titleCell2.setCellStyle(cellHeadStyle); Cell titleCell3 = headRow.createCell(2); titleCell3.setCellValue("Department"); titleCell3.setCellStyle(cellHeadStyle); Cell titleCell4 = headRow.createCell(3); titleCell4.setCellValue(departmentName); titleCell4.setCellStyle(cellHeadStyle); Cell titleCell5 = headRow.createCell(4); titleCell5.setCellValue("name: " + fullName); titleCell5.setCellStyle(cellHeadStyle); Cell titleCell6 = headRow.createCell(5); titleCell6.setCellValue("Annual assessment: " + year); titleCell6.setCellStyle(cellHeadStyle); row++; headRow = sh.createRow(row); titleCell1 = headRow.createCell(0); titleCell1.setCellValue(BscReportPropertyUtils.getObjectiveTitle()); titleCell1.setCellStyle(cellHeadStyle); titleCell2 = headRow.createCell(1); titleCell2.setCellValue(BscReportPropertyUtils.getKpiTitle()); titleCell2.setCellStyle(cellHeadStyle); titleCell3 = headRow.createCell(2); titleCell3.setCellValue("Maximum\nTarget\nMinimum"); titleCell3.setCellStyle(cellHeadStyle); titleCell4 = headRow.createCell(3); titleCell4.setCellValue("Weight"); titleCell4.setCellStyle(cellHeadStyle); titleCell5 = headRow.createCell(4); titleCell5.setCellValue("Formula"); titleCell5.setCellStyle(cellHeadStyle); titleCell6 = headRow.createCell(5); titleCell6.setCellValue("Score"); titleCell6.setCellStyle(cellHeadStyle); row++; headRow = sh.createRow(row); headRow.setHeight((short) 1000); titleCell1 = headRow.createCell(0); titleCell1.setCellValue("Objective of Strategy"); titleCell1.setCellStyle(cellHeadStyle); titleCell2 = headRow.createCell(1); titleCell2.setCellValue("KPI"); titleCell2.setCellStyle(cellHeadStyle); titleCell3 = headRow.createCell(2); titleCell3.setCellValue("Target"); titleCell3.setCellStyle(cellHeadStyle); titleCell4 = headRow.createCell(3); titleCell4.setCellValue("Weight"); titleCell4.setCellStyle(cellHeadStyle); titleCell5 = headRow.createCell(4); titleCell5.setCellValue("Formula"); titleCell5.setCellStyle(cellHeadStyle); XSSFCellStyle titleStyle = wb.createCellStyle(); titleStyle.setFillForegroundColor(bgColor); titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); titleStyle.setFillForegroundColor(new XSSFColor(SimpleUtils.getColorRGB4POIColor("#F5F4F4"))); titleStyle.setFont(cellHeadFont); titleStyle.setBorderBottom(BorderStyle.THIN); titleStyle.setBorderTop(BorderStyle.THIN); titleStyle.setBorderRight(BorderStyle.THIN); titleStyle.setBorderLeft(BorderStyle.THIN); titleStyle.setVerticalAlignment(VerticalAlignment.CENTER); titleStyle.setAlignment(HorizontalAlignment.CENTER); titleStyle.setWrapText(true); titleCell6 = headRow.createCell(5); titleCell6.setCellValue(dateTypeName); titleCell6.setCellStyle(titleStyle); for (int i = 0; i < 5; i++) { sh.addMergedRegion(new CellRangeAddress(row - 1, row, i, i)); } return 5; }
From source file:com.netsteadfast.greenstep.bsc.command.PersonalReportExcelCommand.java
License:Apache License
private int createMainBody(XSSFWorkbook wb, XSSFSheet sh, int row, VisionVO vision, Context context) throws Exception { int mrRow = row; XSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setFillForegroundColor(new XSSFColor(SimpleUtils.getColorRGB4POIColor("#ffffff"))); cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); XSSFFont cellFont = wb.createFont(); cellFont.setBold(false);// ww w. ja v a 2s . c o m cellFont.setColor(new XSSFColor(SimpleUtils.getColorRGB4POIColor("#000000"))); cellStyle.setFont(cellFont); cellStyle.setWrapText(true); cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); cellStyle.setBorderBottom(BorderStyle.THIN); cellStyle.setBorderTop(BorderStyle.THIN); cellStyle.setBorderRight(BorderStyle.THIN); cellStyle.setBorderLeft(BorderStyle.THIN); cellStyle.setWrapText(true); for (PerspectiveVO perspective : vision.getPerspectives()) { for (ObjectiveVO objective : perspective.getObjectives()) { for (KpiVO kpi : objective.getKpis()) { int kCol = 0; Row contentRow = sh.createRow(row++); contentRow.setHeight((short) 1000); Cell contentCell1 = contentRow.createCell(kCol++); contentCell1.setCellValue(objective.getName()); contentCell1.setCellStyle(cellStyle); Cell contentCell2 = contentRow.createCell(kCol++); contentCell2.setCellValue(kpi.getName()); contentCell2.setCellStyle(cellStyle); Cell contentCell3 = contentRow.createCell(kCol++); contentCell3.setCellValue("max: " + kpi.getMax() + "\n" + "target: " + kpi.getTarget() + "\n" + "min: " + kpi.getMin() + "\n" + "unit: " + kpi.getUnit()); contentCell3.setCellStyle(cellStyle); Cell contentCell4 = contentRow.createCell(kCol++); contentCell4.setCellValue(kpi.getWeight() + "%"); contentCell4.setCellStyle(cellStyle); Cell contentCell5 = contentRow.createCell(kCol++); contentCell5.setCellValue(kpi.getFormula().getName()); contentCell5.setCellStyle(cellStyle); DateRangeScoreVO dateRangeScore = kpi.getDateRangeScores().get(0); // ? XSSFCellStyle cellStyleScore = wb.createCellStyle(); cellStyleScore.setFillForegroundColor( new XSSFColor(SimpleUtils.getColorRGB4POIColor(dateRangeScore.getBgColor()))); cellStyleScore.setFillPattern(FillPatternType.SOLID_FOREGROUND); XSSFFont cellScoreFont = wb.createFont(); cellScoreFont.setBold(false); cellScoreFont.setColor( new XSSFColor(SimpleUtils.getColorRGB4POIColor(dateRangeScore.getFontColor()))); cellStyleScore.setFont(cellScoreFont); cellStyleScore.setWrapText(true); cellStyleScore.setVerticalAlignment(VerticalAlignment.CENTER); cellStyleScore.setBorderBottom(BorderStyle.THIN); cellStyleScore.setBorderTop(BorderStyle.THIN); cellStyleScore.setBorderRight(BorderStyle.THIN); cellStyleScore.setBorderLeft(BorderStyle.THIN); Cell contentCell6 = contentRow.createCell(kCol++); contentCell6.setCellValue(BscReportSupportUtils.parse2(dateRangeScore.getScore())); contentCell6.setCellStyle(cellStyleScore); } } } for (PerspectiveVO perspective : vision.getPerspectives()) { for (ObjectiveVO objective : perspective.getObjectives()) { int rowspan = objective.getRow(); if (objective.getRow() > 1) { // 2016-12-13 old work with POI 3.12 //sh.addMergedRegion(new CellRangeAddress(mrRow, mrRow+rowspan-1, 0, 0)); // 2016-12-13 new work with POI 3.15 int mrRow1 = mrRow + rowspan - 1; if (mrRow1 > mrRow) { sh.addMergedRegion(new CellRangeAddress(mrRow, mrRow1, 0, 0)); } } mrRow += rowspan; } } return row; }
From source file:com.netsteadfast.greenstep.bsc.command.PersonalReportExcelCommand.java
License:Apache License
private void createFoot(XSSFWorkbook wb, XSSFSheet sh, int row, VisionVO vision, Context context) throws Exception { Row footRow = sh.createRow(row);//from ww w . j ava 2s. c om 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); }
From source file:com.netsteadfast.greenstep.bsc.command.PerspectivesDashboardExcelCommand.java
License:Apache License
@SuppressWarnings("unchecked") private int putCharts(XSSFWorkbook wb, XSSFSheet sh, Context context) throws Exception { String pieBase64Content = SimpleUtils.getPNGBase64Content((String) context.get("pieCanvasToData")); String barBase64Content = SimpleUtils.getPNGBase64Content((String) context.get("barCanvasToData")); BufferedImage pieImage = SimpleUtils.decodeToImage(pieBase64Content); BufferedImage barImage = SimpleUtils.decodeToImage(barBase64Content); ByteArrayOutputStream pieBos = new ByteArrayOutputStream(); ImageIO.write(pieImage, "png", pieBos); pieBos.flush();/* w w w .j a v a2 s . c om*/ ByteArrayOutputStream barBos = new ByteArrayOutputStream(); ImageIO.write(barImage, "png", barBos); barBos.flush(); SimpleUtils.setCellPicture(wb, sh, pieBos.toByteArray(), 0, 0); SimpleUtils.setCellPicture(wb, sh, barBos.toByteArray(), 0, 9); int row = 21; List<Map<String, Object>> chartDatas = (List<Map<String, Object>>) context.get("chartDatas"); String year = (String) context.get("year"); XSSFCellStyle cellHeadStyle = wb.createCellStyle(); cellHeadStyle.setFillForegroundColor(new XSSFColor(SimpleUtils.getColorRGB4POIColor("#f5f5f5"))); cellHeadStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); XSSFFont cellHeadFont = wb.createFont(); cellHeadFont.setBold(true); //cellHeadFont.setColor( new XSSFColor( SimpleUtils.getColorRGB4POIColor( "#000000" ) ) ); cellHeadStyle.setFont(cellHeadFont); int titleRow = row - 1; int titleCellSize = 14; Row headRow = sh.createRow(titleRow); for (int i = 0; i < titleCellSize; i++) { Cell headCell = headRow.createCell(i); headCell.setCellStyle(cellHeadStyle); headCell.setCellValue("Perspectives metrics gauge ( " + year + " )"); } sh.addMergedRegion(new CellRangeAddress(titleRow, titleRow, 0, titleCellSize - 1)); int cellLeft = 10; int rowSpace = 17; for (Map<String, Object> data : chartDatas) { Map<String, Object> nodeData = (Map<String, Object>) ((List<Object>) data.get("datas")).get(0); String pngImageData = SimpleUtils.getPNGBase64Content((String) nodeData.get("outerHTML")); BufferedImage imageData = SimpleUtils.decodeToImage(pngImageData); ByteArrayOutputStream imgBos = new ByteArrayOutputStream(); ImageIO.write(imageData, "png", imgBos); imgBos.flush(); SimpleUtils.setCellPicture(wb, sh, imgBos.toByteArray(), row, 0); XSSFColor bgColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor((String) nodeData.get("bgColor"))); XSSFColor fnColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor((String) nodeData.get("fontColor"))); XSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setFillForegroundColor(bgColor); cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); XSSFFont cellFont = wb.createFont(); cellFont.setBold(true); cellFont.setColor(fnColor); cellStyle.setFont(cellFont); int perTitleCellSize = 4; Row nowRow = sh.createRow(row); for (int i = 0; i < perTitleCellSize; i++) { Cell cell1 = nowRow.createCell(cellLeft); cell1.setCellStyle(cellStyle); cell1.setCellValue((String) nodeData.get("name")); } sh.addMergedRegion(new CellRangeAddress(row, row, cellLeft, cellLeft + perTitleCellSize - 1)); nowRow = sh.createRow(row + 1); Cell cell2 = nowRow.createCell(cellLeft); cell2.setCellValue("Target: " + String.valueOf(nodeData.get("target"))); nowRow = sh.createRow(row + 2); Cell cell3 = nowRow.createCell(cellLeft); cell3.setCellValue("Min: " + String.valueOf(nodeData.get("min"))); nowRow = sh.createRow(row + 3); Cell cell4 = nowRow.createCell(cellLeft); cell4.setCellValue("Score: " + String.valueOf(nodeData.get("score"))); row += rowSpace; } return row; }
From source file:com.saba.CalendarDemo.java
License:Apache License
private static void prepareContactDetailsTableAndData(Map<String, Object> data, XSSFSheet sheet, Map<String, CellStyle> styles) { XSSFRow titleRow = sheet.createRow(0); titleRow.setHeightInPoints(16);/*w w w. j ava 2s. c om*/ for (int i = 0; i <= 1; i++) { titleRow.createCell(i).setCellStyle(styles.get("title")); } XSSFCell titleCell = titleRow.getCell(0); titleCell.setCellValue(awardHeaders[0].toString()); sheet.addMergedRegion(CellRangeAddress.valueOf("$A$1:$B$1")); for (int i = 0; i < contactDetails.length; i++) { XSSFRow row = sheet.createRow(i + 1); XSSFCell cell = row.createCell(0); cell.setCellValue(contactDetails[i].toString()); cell.setCellStyle(styles.get("item_left")); cell = row.createCell(1); populateDynamicObject(cell, data.get(contactDetails[i])); cell.setCellStyle(styles.get("item_right")); } }
From source file:com.saba.CalendarDemo.java
License:Apache License
private static void prepareAwardBidDetailsTableAndData(Map<String, Object> data, XSSFSheet sheet, Map<String, CellStyle> styles, int contactdetrow) { XSSFRow titleRow;//from w w w . j av a2 s . c o m XSSFCell titleCell; titleRow = sheet.createRow(contactdetrow); titleRow.setHeightInPoints(16); for (int i = 0; i <= 1; i++) { titleRow.createCell(i).setCellStyle(styles.get("title")); } titleCell = titleRow.getCell(0); titleCell.setCellValue(awardHeaders[1].toString()); sheet.addMergedRegion(CellRangeAddress.valueOf("$A$" + (contactdetrow + 1) + ":$B$" + (contactdetrow + 1))); for (int i = 0; i < awardedBidDetails.length; i++) { XSSFRow row = sheet.createRow(contactdetrow + i + 1); XSSFCell cell = row.createCell(0); cell.setCellValue(awardedBidDetails[i]); cell.setCellStyle(styles.get("item_left")); cell = row.createCell(1); populateDynamicObject(cell, data.get(awardedBidDetails[i])); cell.setCellStyle(styles.get("item_right")); } }
From source file:com.saba.CalendarDemo.java
License:Apache License
private static void prepareProductDetailsTable(XSSFWorkbook workbook, XSSFSheet sheet, Map<String, CellStyle> styles, int awardDetailsRow) { XSSFRow titleRow;/*from ww w .jav a 2 s.com*/ XSSFCell titleCell; titleRow = sheet.createRow(awardDetailsRow); titleRow.setHeightInPoints(16); for (int i = 0; i < productDetailsHeaders.length; i++) { titleRow.createCell(i).setCellStyle(styles.get("title")); } titleCell = titleRow.getCell(0); titleCell.setCellValue(awardHeaders[2].toString()); String columId = productDetailsHeaders.length > 0 && productDetailsHeaders.length < 27 ? String.valueOf((char) (productDetailsHeaders.length + 'A' - 1)) : null; String cellMergeRange = "$A$" + (awardDetailsRow + 1) + ":$" + columId + "$" + (awardDetailsRow + 1); sheet.addMergedRegion(CellRangeAddress.valueOf(cellMergeRange)); XSSFRow row = sheet.createRow(awardDetailsRow + 1); for (int i = 0; i < productDetailsHeaders.length; i++) { XSSFCell cell = row.createCell(i); cell.setCellValue(productDetailsHeaders[i]); //create header style for product Details table CellStyle headerStyle = createHeaderStyleForAward(workbook); cell.setCellStyle(headerStyle); } }
From source file:com.solidmaps.webapp.report.utils.ExcelMapCivilGenerator.java
private void createCellProduct(XSSFSheet sheetBuy, XSSFRow row, Integer index, String value) { XSSFCell cell = row.createCell(index); sheetBuy.addMergedRegion(new CellRangeAddress(row.getRowNum(), row.getRowNum(), 0, 3)); cell.setCellStyle(styleProductList); cell.setCellValue(value);//from w ww. ja va2 s . co m }
From source file:com.solidmaps.webapp.report.utils.ExcelMapCivilGenerator.java
private void createCellUtilization(XSSFSheet sheetBuy, XSSFRow row, String value) { XSSFCell cell = row.createCell(7);/*from w w w . j a v a 2s .c o m*/ sheetBuy.addMergedRegion(new CellRangeAddress(row.getRowNum(), row.getRowNum(), 7, 8)); cell.setCellStyle(styleProductList); cell.setCellValue(value); }
From source file:com.solidmaps.webapp.report.utils.ExcelMapCivilGenerator.java
private void createCellSell(XSSFSheet sheetBuy, XSSFRow row, String value) { XSSFCell cell = row.createCell(9);/*from ww w . j a v a 2 s. com*/ sheetBuy.addMergedRegion(new CellRangeAddress(row.getRowNum(), row.getRowNum(), 9, 11)); cell.setCellStyle(styleProductList); cell.setCellValue(value); }