List of usage examples for org.apache.poi.hssf.usermodel HSSFCellStyle setBorderTop
@Override public void setBorderTop(BorderStyle border)
From source file:net.sf.jasperreports.engine.export.JRXlsMetadataExporter.java
License:Open Source License
protected HSSFCellStyle getLoadedCellStyle(StyleInfo style) { HSSFCellStyle cellStyle = loadedCellStyles.get(style); if (cellStyle == null) { cellStyle = workbook.createCellStyle(); cellStyle.setFillForegroundColor(style.backcolor); cellStyle.setFillPattern(style.mode); cellStyle.setAlignment(style.horizontalAlignment); cellStyle.setVerticalAlignment(style.verticalAlignment); cellStyle.setRotation(style.rotation); cellStyle.setFont(style.font);//from www . j a v a 2 s. c o m cellStyle.setWrapText(style.lcWrapText); cellStyle.setLocked(style.lcCellLocked); cellStyle.setHidden(style.lcCellHidden); if (style.hasDataFormat()) { cellStyle.setDataFormat(style.getDataFormat()); } if (!getCurrentItemConfiguration().isIgnoreCellBorder()) { BoxStyle box = style.box; cellStyle.setBorderTop(box.borderStyle[BoxStyle.TOP]); cellStyle.setTopBorderColor(box.borderColour[BoxStyle.TOP]); cellStyle.setBorderLeft(box.borderStyle[BoxStyle.LEFT]); cellStyle.setLeftBorderColor(box.borderColour[BoxStyle.LEFT]); cellStyle.setBorderBottom(box.borderStyle[BoxStyle.BOTTOM]); cellStyle.setBottomBorderColor(box.borderColour[BoxStyle.BOTTOM]); cellStyle.setBorderRight(box.borderStyle[BoxStyle.RIGHT]); cellStyle.setRightBorderColor(box.borderColour[BoxStyle.RIGHT]); } loadedCellStyles.put(style, cellStyle); } return cellStyle; }
From source file:org.adempiere.impexp.AbstractExcelExporter.java
License:Open Source License
private HSSFCellStyle getStyle(int row, int col) { int displayType = getDisplayType(row, col); String key = "cell-" + col + "-" + displayType; HSSFCellStyle cs = m_styles.get(key); if (cs == null) { boolean isHighlightNegativeNumbers = true; cs = m_workbook.createCellStyle(); HSSFFont font = getFont(false);/*from ww w .jav a2s .c o m*/ cs.setFont(font); // Border cs.setBorderLeft((short) 1); cs.setBorderTop((short) 1); cs.setBorderRight((short) 1); cs.setBorderBottom((short) 1); // if (DisplayType.isDate(displayType)) { cs.setDataFormat(m_dataFormat.getFormat("DD.MM.YYYY")); } else if (DisplayType.isNumeric(displayType)) { DecimalFormat df = DisplayType.getNumberFormat(displayType, getLanguage()); String format = getFormatString(df, isHighlightNegativeNumbers); cs.setDataFormat(m_dataFormat.getFormat(format)); } m_styles.put(key, cs); } return cs; }
From source file:org.adempiere.impexp.AbstractExcelExporter.java
License:Open Source License
private HSSFCellStyle getHeaderStyle(int col) { String key = "header-" + col; HSSFCellStyle cs_header = m_styles.get(key); if (cs_header == null) { HSSFFont font_header = getFont(true); cs_header = m_workbook.createCellStyle(); cs_header.setFont(font_header);//ww w. j ava 2 s . c o m cs_header.setBorderLeft((short) 2); cs_header.setBorderTop((short) 2); cs_header.setBorderRight((short) 2); cs_header.setBorderBottom((short) 2); cs_header.setDataFormat(HSSFDataFormat.getBuiltinFormat("text")); cs_header.setWrapText(true); m_styles.put(key, cs_header); } return cs_header; }
From source file:org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPTop.java
License:Apache License
/** * Override of Initialize() implementation * @param attributes the array of Attribute instances; may be empty, will * never be null/*from w w w . j av a 2 s. co m*/ * @param parent the parent ElementProcessor; may be null * @exception IOException if anything is wrong */ public void initialize(final Attribute[] attributes, final ElementProcessor parent) throws IOException { super.initialize(attributes, parent); EPStyle pstyle = (EPStyle) getAncestor(EPStyle.class); if (pstyle != null && pstyle.isValid()) { Hashtable colorhash = pstyle.getColorHash(); HSSFColor color = null; HSSFCellStyle style = pstyle.getStyle(); //oops // a // little // confusing //below is the style attribute //this is an HSSFCellStyle //associated with EPStyle style.setBorderTop((short) getStyle()); ColorCode colorCode = getColor(); if (colorCode != null) { color = (HSSFColor) colorhash.get(colorCode.toString()); } if (color == null) color = new HSSFColor.BLACK(); style.setTopBorderColor(color.getIndex()); } }
From source file:org.deployom.core.AuditService.java
License:Open Source License
public HSSFWorkbook saveAudit() { // Create book HSSFWorkbook workbook = new HSSFWorkbook(); HSSFCreationHelper creationHelper = workbook.getCreationHelper(); // Default Style HSSFCellStyle style = workbook.createCellStyle(); style.setWrapText(true);/*from www . j av a 2 s.c o m*/ HSSFFont font = workbook.createFont(); font.setFontName("Courier New"); style.setFont(font); style.setBorderBottom(HSSFCellStyle.BORDER_THIN); style.setBorderTop(HSSFCellStyle.BORDER_THIN); style.setBorderRight(HSSFCellStyle.BORDER_THIN); style.setBorderLeft(HSSFCellStyle.BORDER_THIN); // Header Style HSSFCellStyle styleHeader = workbook.createCellStyle(); styleHeader.cloneStyleFrom(style); styleHeader.setAlignment(HSSFCellStyle.ALIGN_CENTER); font = workbook.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); font.setColor(HSSFColor.WHITE.index); styleHeader.setFillForegroundColor(IndexedColors.BLACK.getIndex()); styleHeader.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); styleHeader.setFont(font); // Error Style HSSFCellStyle styleError = workbook.createCellStyle(); styleError.cloneStyleFrom(style); styleError.setFillForegroundColor(IndexedColors.CORAL.getIndex()); styleError.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); styleError.setWrapText(true); // Link Style HSSFCellStyle styleLink = workbook.createCellStyle(); styleLink.cloneStyleFrom(style); font = workbook.createFont(); font.setUnderline(HSSFFont.U_SINGLE); font.setColor(IndexedColors.BLUE.getIndex()); styleLink.setFont(font); // Create Summary HSSFSheet summarySheet = workbook.createSheet("Summary"); int summaryRownum = 0; int summaryCellnum = 0; //Create a new row in current sheet Row summaryRow = summarySheet.createRow(summaryRownum++); // 0 Cell summaryCell = summaryRow.createCell(summaryCellnum++); summaryCell.setCellValue("Job"); summaryCell.setCellStyle(styleHeader); // 1 summaryCell = summaryRow.createCell(summaryCellnum++); summaryCell.setCellValue("Finished"); summaryCell.setCellStyle(styleHeader); // 2 summaryCell = summaryRow.createCell(summaryCellnum++); summaryCell.setCellValue("Errors"); summaryCell.setCellStyle(styleHeader); for (Job job : releaseService.getJobs()) { // Open Job JobService jobService = new JobService(siteService.getSiteName(), job.getJobName()); // Create Sheet HSSFSheet sheet = workbook.createSheet(job.getJobName()); int rownum = 0; int cellnum = 0; int errors = 0; //Create a new row in current sheet Row row = sheet.createRow(rownum++); // 0 Cell cell = row.createCell(cellnum++); cell.setCellValue("Host"); cell.setCellStyle(styleHeader); // 1 cell = row.createCell(cellnum++); cell.setCellValue("Service"); cell.setCellStyle(styleHeader); // 2 cell = row.createCell(cellnum++); cell.setCellValue("Command"); cell.setCellStyle(styleHeader); // 3 cell = row.createCell(cellnum++); cell.setCellValue("Executable"); cell.setCellStyle(styleHeader); // 4 cell = row.createCell(cellnum++); cell.setCellValue("Error"); cell.setCellStyle(styleHeader); // 5 cell = row.createCell(cellnum++); cell.setCellValue("Output"); cell.setCellStyle(styleHeader); // Check all hosts for (Host host : jobService.getHosts()) { // Check all services for (Service service : host.getServices()) { // Get a Commands for (Command command : service.getCommands()) { //Create a new row in current sheet row = sheet.createRow(rownum++); cellnum = 0; // 0 cell = row.createCell(cellnum++); cell.setCellValue(host.getHostName()); cell.setCellStyle(style); // 1 cell = row.createCell(cellnum++); cell.setCellValue(service.getServiceName()); cell.setCellStyle(style); // 2 cell = row.createCell(cellnum++); cell.setCellValue(command.getTitle()); cell.setCellStyle(style); // 3 cell = row.createCell(cellnum++); cell.setCellValue(command.getExec()); cell.setCellStyle(style); // 4 cell = row.createCell(cellnum++); cell.setCellValue("N"); cell.setCellStyle(style); // 5 cell = row.createCell(cellnum++); if (command.getOut().length() > 1024) { cell.setCellValue(command.getOut().substring(0, 1024) + "..."); } else { cell.setCellValue(command.getOut()); } cell.setCellStyle(style); // Error if (command.isError() == true) { row.getCell(0).setCellStyle(styleError); row.getCell(1).setCellStyle(styleError); row.getCell(2).setCellStyle(styleError); row.getCell(3).setCellStyle(styleError); row.getCell(4).setCellStyle(styleError); row.getCell(5).setCellStyle(styleError); row.getCell(4).setCellValue("Y"); errors++; } } } } // Set Size sheet.setColumnWidth(0, 6000); sheet.setColumnWidth(1, 4000); sheet.setColumnWidth(2, 8000); sheet.setColumnWidth(3, 14000); sheet.setColumnWidth(4, 3000); sheet.setColumnWidth(5, 20000); // Summary summaryRow = summarySheet.createRow(summaryRownum++); summaryCellnum = 0; // 0 summaryCell = summaryRow.createCell(summaryCellnum++); summaryCell.setCellValue(job.getJobName()); summaryCell.setCellStyle(style); // Set Link HSSFHyperlink link = creationHelper.createHyperlink(Hyperlink.LINK_DOCUMENT); link.setAddress("" + job.getJobName() + "!A1"); summaryCell.setHyperlink(link); summaryCell.setCellStyle(styleLink); // 1 summaryCell = summaryRow.createCell(summaryCellnum++); summaryCell.setCellValue(jobService.getJob().getFinished()); summaryCell.setCellStyle(style); // 2 summaryCell = summaryRow.createCell(summaryCellnum++); summaryCell.setCellValue(errors); summaryCell.setCellStyle(style); // If errors found if (errors > 0) { summaryRow.getCell(0).setCellStyle(styleError); summaryRow.getCell(1).setCellStyle(styleError); summaryRow.getCell(2).setCellStyle(styleError); } } // Set Summary Size summarySheet.setColumnWidth(0, 6000); summarySheet.setColumnWidth(1, 10000); summarySheet.setColumnWidth(2, 4000); // Save try { FileOutputStream out = new FileOutputStream(new File(getFileName())); workbook.write(out); out.close(); logger.log(Level.INFO, "{0} generated successfully..", getFileName()); return workbook; } catch (FileNotFoundException ex) { logger.log(Level.WARNING, "Audit: {0}", ex); } catch (IOException ex) { logger.log(Level.WARNING, "Audit: {0}", ex); } return null; }
From source file:org.extremecomponents.table.view.ExtendXlsView.java
License:Apache License
private Map initStyles(HSSFWorkbook wb, short fontHeight) { Map result = new HashMap(); HSSFCellStyle titleStyle = wb.createCellStyle(); HSSFCellStyle textStyle = wb.createCellStyle(); HSSFCellStyle boldStyle = wb.createCellStyle(); HSSFCellStyle numericStyle = wb.createCellStyle(); HSSFCellStyle numericStyleBold = wb.createCellStyle(); HSSFCellStyle moneyStyle = wb.createCellStyle(); HSSFCellStyle moneyStyleBold = wb.createCellStyle(); HSSFCellStyle percentStyle = wb.createCellStyle(); HSSFCellStyle percentStyleBold = wb.createCellStyle(); result.put("titleStyle", titleStyle); result.put("textStyle", textStyle); result.put("boldStyle", boldStyle); result.put("numericStyle", numericStyle); result.put("numericStyleBold", numericStyleBold); result.put("moneyStyle", moneyStyle); result.put("moneyStyleBold", moneyStyleBold); result.put("percentStyle", percentStyle); result.put("percentStyleBold", percentStyleBold); HSSFDataFormat format = wb.createDataFormat(); // Global fonts HSSFFont font = wb.createFont();/*from ww w . j a v a 2 s .c om*/ font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); font.setColor(HSSFColor.BLACK.index); font.setFontName(HSSFFont.FONT_ARIAL); font.setFontHeightInPoints(fontHeight); HSSFFont fontBold = wb.createFont(); fontBold.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); fontBold.setColor(HSSFColor.BLACK.index); fontBold.setFontName(HSSFFont.FONT_ARIAL); fontBold.setFontHeightInPoints(fontHeight); // Money Style moneyStyle.setFont(font); moneyStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT); moneyStyle.setDataFormat(format.getFormat(moneyFormat)); // Money Style Bold moneyStyleBold.setFont(fontBold); moneyStyleBold.setAlignment(HSSFCellStyle.ALIGN_RIGHT); moneyStyleBold.setDataFormat(format.getFormat(moneyFormat)); // Percent Style percentStyle.setFont(font); percentStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT); percentStyle.setDataFormat(format.getFormat(percentFormat)); // Percent Style Bold percentStyleBold.setFont(fontBold); percentStyleBold.setAlignment(HSSFCellStyle.ALIGN_RIGHT); percentStyleBold.setDataFormat(format.getFormat(percentFormat)); // Standard Numeric Style numericStyle.setFont(font); numericStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT); // Standard Numeric Style Bold numericStyleBold.setFont(fontBold); numericStyleBold.setAlignment(HSSFCellStyle.ALIGN_RIGHT); // Title Style titleStyle.setFont(font); titleStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); titleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); titleStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); titleStyle.setBottomBorderColor(HSSFColor.BLACK.index); titleStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); titleStyle.setLeftBorderColor(HSSFColor.BLACK.index); titleStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); titleStyle.setRightBorderColor(HSSFColor.BLACK.index); titleStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); titleStyle.setTopBorderColor(HSSFColor.BLACK.index); titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); titleStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // Standard Text Style textStyle.setFont(font); textStyle.setWrapText(true); // Standard Text Style boldStyle.setFont(fontBold); boldStyle.setWrapText(true); return result; }
From source file:org.hil.children.service.impl.ChildrenManagerImpl.java
License:Open Source License
public String printListVaccinationReport(String type, String timeFrom, String timeTo, Commune commune, District district, List<RegionVaccinationReportData> statistics) { String path = ""; String prefixFileName = ""; if (commune != null) prefixFileName = commune.getDistrict().getProvince().getProvinceId() + commune.getDistrict().getDistrictId() + commune.getCommuneId(); else/*w ww . j av a 2s . c o m*/ prefixFileName = district.getProvince().getProvinceId() + district.getDistrictId(); GraniteContext gc = GraniteContext.getCurrentInstance(); ServletContext sc = ((HttpGraniteContext) gc).getServletContext(); String reportDir = sc.getRealPath(config.getBaseReportDir()); long currentTime = System.currentTimeMillis(); String filePath = reportDir + "/" + prefixFileName + "_Report_" + currentTime; if (type.equalsIgnoreCase("pdf")) { JasperPrint reportPrint = createListVaccinationReportPrint(timeFrom, timeTo, commune, district, statistics); try { filePath += ".pdf"; JasperExportManager.exportReportToPdfFile(reportPrint, filePath); path = "/reports/" + prefixFileName + "_Report_" + currentTime + ".pdf"; log.debug("path to pdf report:" + path); } catch (Exception ex) { String connectMsg = "Could not create the report " + ex.getMessage() + " " + ex.getLocalizedMessage(); log.debug(connectMsg); } } else { filePath += ".xls"; POIFSFileSystem fs; String regionName = ""; String provinceName = ""; String districtName = ""; String communeName = ""; String timeData = ""; Short rId = 0; if (commune != null) { communeName = commune.getCommuneName(); provinceName = commune.getDistrict().getProvince().getProvinceName(); districtName = commune.getDistrict().getDistrictName(); rId = commune.getDistrict().getProvince().getRegionId(); } else if (district != null) { provinceName = district.getProvince().getProvinceName(); districtName = district.getDistrictName(); rId = district.getProvince().getRegionId(); } if (rId == 1) regionName = "Mi?n Bc"; else if (rId == 2) regionName = "Mi?n Trung"; else regionName = "Mi?n Nam"; if (timeFrom.equalsIgnoreCase(timeTo)) { timeData = timeTo; } else { timeData = timeFrom + " - " + timeTo; } try { fs = new POIFSFileSystem(new FileInputStream(reportDir + "/excel/TCMR_Report_Template.xls")); HSSFWorkbook wb = new HSSFWorkbook(fs, true); HSSFSheet s = wb.getSheetAt(0); HSSFRow r = null; HSSFCell c = null; r = s.getRow(4); c = r.getCell(1); c.setCellValue(c.getStringCellValue() + " " + regionName.toUpperCase()); r = s.getRow(5); c = r.getCell(1); c.setCellValue(c.getStringCellValue() + " " + provinceName.toUpperCase()); r = s.getRow(6); c = r.getCell(1); c.setCellValue(c.getStringCellValue() + " " + districtName.toUpperCase()); r = s.getRow(7); c = r.getCell(1); c.setCellValue(c.getStringCellValue() + " " + communeName.toUpperCase()); r = s.getRow(4); c = r.getCell(15); c.setCellValue(timeData); HSSFCellStyle cs = wb.createCellStyle(); cs.setBorderBottom(HSSFCellStyle.BORDER_THIN); cs.setBorderTop(HSSFCellStyle.BORDER_THIN); cs.setBorderLeft(HSSFCellStyle.BORDER_THIN); cs.setBorderRight(HSSFCellStyle.BORDER_THIN); HSSFCellStyle cs1 = wb.createCellStyle(); cs1.setBorderBottom(HSSFCellStyle.BORDER_THIN); cs1.setBorderTop(HSSFCellStyle.BORDER_THIN); cs1.setBorderLeft(HSSFCellStyle.BORDER_THIN); cs1.setBorderRight(HSSFCellStyle.BORDER_THIN); cs1.setAlignment(HSSFCellStyle.ALIGN_CENTER); int rownum = 13; for (rownum = 13; rownum < statistics.size() + 11; rownum++) { if (rownum < statistics.size() + 10) copyRow(wb, s, rownum, rownum + 1); r = s.getRow(rownum); r.setHeight((short) 270); c = r.getCell(1); c.setCellValue(rownum - 12); c = r.getCell(3); c.setCellValue(statistics.get(rownum - 13).getRegionName()); c = r.getCell(6); c.setCellValue(statistics.get(rownum - 13).getChildrenUnder1() == null ? 0 : statistics.get(rownum - 13).getChildrenUnder1()); c = r.getCell(8); c.setCellValue(statistics.get(rownum - 13).getBCG() + " (" + statistics.get(rownum - 13).geteBCG() + ")"); c = r.getCell(10); c.setCellValue(statistics.get(rownum - 13).getVGBL24() + " (" + statistics.get(rownum - 13).geteVGBL24() + ")"); c = r.getCell(11); c.setCellValue(statistics.get(rownum - 13).getVGBG24() + " (" + statistics.get(rownum - 13).geteVGBG24() + ")"); c = r.getCell(14); c.setCellValue(statistics.get(rownum - 13).getDPT_VGB_Hib1() + " (" + statistics.get(rownum - 13).geteDPT_VGB_Hib1() + ")"); c = r.getCell(16); c.setCellValue(statistics.get(rownum - 13).getDPT_VGB_Hib2() + " (" + statistics.get(rownum - 13).geteDPT_VGB_Hib2() + ")"); c = r.getCell(18); c.setCellValue(statistics.get(rownum - 13).getDPT_VGB_Hib3() + " (" + statistics.get(rownum - 13).geteDPT_VGB_Hib3() + ")"); c = r.getCell(19); c.setCellValue(statistics.get(rownum - 13).getOPV1() + " (" + statistics.get(rownum - 13).geteOPV1() + ")"); c = r.getCell(20); c.setCellValue(statistics.get(rownum - 13).getOPV2() + " (" + statistics.get(rownum - 13).geteOPV2() + ")"); c = r.getCell(21); c.setCellValue(statistics.get(rownum - 13).getOPV3() + " (" + statistics.get(rownum - 13).geteOPV3() + ")"); c = r.getCell(23); c.setCellValue(statistics.get(rownum - 13).getMeasles1() + " (" + statistics.get(rownum - 13).geteMeasles1() + ")"); c = r.getCell(25); c.setCellValue(statistics.get(rownum - 13).getAmountOfFinish()); c = r.getCell(27); c.setCellValue(statistics.get(rownum - 13).getProtectedTetanusCases() == null ? 0 : statistics.get(rownum - 13).getProtectedTetanusCases()); c = r.getCell(28); c.setCellValue(statistics.get(rownum - 13).getReactionNormalCases() == null ? 0 : statistics.get(rownum - 13).getReactionNormalCases()); c = r.getCell(30); c.setCellValue(statistics.get(rownum - 13).getReactionSeriousCases() == null ? 0 : statistics.get(rownum - 13).getReactionSeriousCases()); } if (statistics != null && statistics.size() > 0) { for (; rownum < statistics.size() + 13; rownum++) { r = s.getRow(rownum); c = r.getCell(6); c.setCellValue(statistics.get(rownum - 13).getChildrenUnder1() == null ? 0 : statistics.get(rownum - 13).getChildrenUnder1()); c = r.getCell(8); c.setCellValue(statistics.get(rownum - 13).getBCG() + "\n(" + statistics.get(rownum - 13).geteBCG() + ")"); c = r.getCell(10); c.setCellValue(statistics.get(rownum - 13).getVGBL24() + "\n(" + statistics.get(rownum - 13).geteVGBL24() + ")"); c = r.getCell(11); c.setCellValue(statistics.get(rownum - 13).getVGBG24() + "\n(" + statistics.get(rownum - 13).geteVGBG24() + ")"); c = r.getCell(14); c.setCellValue(statistics.get(rownum - 13).getDPT_VGB_Hib1() + "\n(" + statistics.get(rownum - 13).geteDPT_VGB_Hib1() + ")"); c = r.getCell(16); c.setCellValue(statistics.get(rownum - 13).getDPT_VGB_Hib2() + "\n(" + statistics.get(rownum - 13).geteDPT_VGB_Hib2() + ")"); c = r.getCell(18); c.setCellValue(statistics.get(rownum - 13).getDPT_VGB_Hib3() + "\n(" + statistics.get(rownum - 13).geteDPT_VGB_Hib3() + ")"); c = r.getCell(19); c.setCellValue(statistics.get(rownum - 13).getOPV1() + "\n(" + statistics.get(rownum - 13).geteOPV1() + ")"); c = r.getCell(20); c.setCellValue(statistics.get(rownum - 13).getOPV2() + "\n(" + statistics.get(rownum - 13).geteOPV2() + ")"); c = r.getCell(21); c.setCellValue(statistics.get(rownum - 13).getOPV3() + "\n(" + statistics.get(rownum - 13).geteOPV3() + ")"); c = r.getCell(23); c.setCellValue(statistics.get(rownum - 13).getMeasles1() + "\n(" + statistics.get(rownum - 13).geteMeasles1() + ")"); c = r.getCell(25); c.setCellValue(statistics.get(rownum - 13).getAmountOfFinish()); c = r.getCell(27); c.setCellValue(statistics.get(rownum - 13).getProtectedTetanusCases() == null ? 0 : statistics.get(rownum - 13).getProtectedTetanusCases()); c = r.getCell(28); c.setCellValue(statistics.get(rownum - 13).getReactionNormalCases() == null ? 0 : statistics.get(rownum - 13).getReactionNormalCases()); c = r.getCell(30); c.setCellValue(statistics.get(rownum - 13).getReactionSeriousCases() == null ? 0 : statistics.get(rownum - 13).getReactionSeriousCases()); r.setHeight((short) 500); } } else { for (; rownum < 16; rownum++) { r = s.getRow(rownum); c = r.getCell(6); c.setCellValue(""); c = r.getCell(8); c.setCellValue(""); c = r.getCell(10); c.setCellValue(""); c = r.getCell(11); c.setCellValue(""); c = r.getCell(14); c.setCellValue(""); c = r.getCell(16); c.setCellValue(""); c = r.getCell(18); c.setCellValue(""); c = r.getCell(19); c.setCellValue(""); c = r.getCell(20); c.setCellValue(""); c = r.getCell(21); c.setCellValue(""); c = r.getCell(23); c.setCellValue(""); c = r.getCell(25); c.setCellValue(""); c = r.getCell(27); c.setCellValue(""); c = r.getCell(28); c.setCellValue(""); c = r.getCell(30); c.setCellValue(""); } } FileOutputStream fileOut = new FileOutputStream(filePath); wb.write(fileOut); fileOut.close(); path = "/reports/" + prefixFileName + "_Report_" + currentTime + ".xls"; log.debug("Excel: " + path); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } return path; }
From source file:org.hil.children.service.impl.ChildrenManagerImpl.java
License:Open Source License
public String printListChildren(ChildrenSearchVO params) { List<ChildrenPrintVO> children = childrenDaoExt.searchChildrenForPrint(params); SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); String strDOBFrom = format.format(params.getDateOfBirthFrom()); String strDOBTo = format.format(params.getDateOfBirthTo()); String path = ""; String prefixFileName = ""; Commune commune = communeDao.get(params.getCommuneId()); prefixFileName = commune.getDistrict().getProvince().getProvinceId() + commune.getDistrict().getDistrictId() + commune.getCommuneId();/*ww w . j av a 2 s. c o m*/ GraniteContext gc = GraniteContext.getCurrentInstance(); ServletContext sc = ((HttpGraniteContext) gc).getServletContext(); String reportDir = sc.getRealPath(config.getBaseReportDir()); long currentTime = System.currentTimeMillis(); String filePath = reportDir + "/" + prefixFileName + "_List_Children_Excel_" + currentTime; POIFSFileSystem fs; try { filePath += ".xls"; fs = new POIFSFileSystem(new FileInputStream(reportDir + "/excel/ListOfChildrenInCommune.xls")); HSSFWorkbook wb = new HSSFWorkbook(fs, true); HSSFSheet s = wb.getSheetAt(0); HSSFRow r = null; HSSFCell c = null; r = s.getRow(0); c = r.getCell(1); c.setCellValue(commune.getCommuneName()); c = r.getCell(2); c.setCellValue("(" + strDOBFrom + " - " + strDOBTo + ")"); HSSFCellStyle cs = wb.createCellStyle(); cs.setBorderBottom(HSSFCellStyle.BORDER_THIN); cs.setBorderTop(HSSFCellStyle.BORDER_THIN); cs.setBorderLeft(HSSFCellStyle.BORDER_THIN); cs.setBorderRight(HSSFCellStyle.BORDER_THIN); HSSFCellStyle cs1 = wb.createCellStyle(); cs1.setBorderBottom(HSSFCellStyle.BORDER_THIN); cs1.setBorderTop(HSSFCellStyle.BORDER_THIN); cs1.setBorderLeft(HSSFCellStyle.BORDER_THIN); cs1.setBorderRight(HSSFCellStyle.BORDER_THIN); cs1.setAlignment(HSSFCellStyle.ALIGN_CENTER); HSSFCellStyle cs2 = wb.createCellStyle(); cs2.setBorderBottom(HSSFCellStyle.BORDER_THIN); cs2.setBorderTop(HSSFCellStyle.BORDER_THIN); cs2.setBorderLeft(HSSFCellStyle.BORDER_THIN); cs2.setBorderRight(HSSFCellStyle.BORDER_THIN); CreationHelper createHelper = wb.getCreationHelper(); cs2.setDataFormat(createHelper.createDataFormat().getFormat("dd/MM/yyyy")); int rownum = 3; for (rownum = 3; rownum < children.size() + 3; rownum++) { r = s.createRow(rownum); c = r.createCell(0); c.setCellStyle(cs1); c.setCellValue(rownum - 2); c = r.createCell(1); c.setCellStyle(cs); c.setCellValue(children.get(rownum - 3).getFullName()); c = r.createCell(2); c.setCellStyle(cs2); c.setCellValue(children.get(rownum - 3).getDateOfBirth()); c = r.createCell(3); c.setCellStyle(cs); c.setCellValue(children.get(rownum - 3).isGender() == true ? "N" : "Nam"); c = r.createCell(4); c.setCellStyle(cs); c.setCellValue(children.get(rownum - 3).getVillageName()); c = r.createCell(5); c.setCellStyle(cs); c.setCellValue(children.get(rownum - 3).getMotherName()); c = r.createCell(6); c.setCellStyle(cs); c.setCellValue(children.get(rownum - 3).getMotherBirthYear() != null ? children.get(rownum - 3).getMotherBirthYear() : 0); c = r.createCell(7); c.setCellStyle(cs); c.setCellValue(children.get(rownum - 3).getMotherMobile()); c = r.createCell(8); c.setCellStyle(cs); c.setCellValue(children.get(rownum - 3).getFatherName()); c = r.createCell(9); c.setCellStyle(cs); c.setCellValue(children.get(rownum - 3).getFatherBirthYear() != null ? children.get(rownum - 3).getFatherBirthYear() : 0); c = r.createCell(10); c.setCellStyle(cs); c.setCellValue(children.get(rownum - 3).getFatherMobile()); c = r.createCell(11); c.setCellStyle(cs); c.setCellValue(children.get(rownum - 3).getCaretakerName()); c = r.createCell(12); c.setCellStyle(cs); c.setCellValue(children.get(rownum - 3).getCaretakerMobile()); c = r.createCell(13); c.setCellStyle(cs2); c.setCellValue(children.get(rownum - 3).getVGB()); c = r.createCell(14); c.setCellStyle(cs2); c.setCellValue(children.get(rownum - 3).getBCG()); c = r.createCell(15); c.setCellStyle(cs2); c.setCellValue(children.get(rownum - 3).getDPT_VGB_Hib1()); c = r.createCell(16); c.setCellStyle(cs2); c.setCellValue(children.get(rownum - 3).getDPT_VGB_Hib2()); c = r.createCell(17); c.setCellStyle(cs2); c.setCellValue(children.get(rownum - 3).getDPT_VGB_Hib3()); c = r.createCell(18); c.setCellStyle(cs2); c.setCellValue(children.get(rownum - 3).getOPV1()); c = r.createCell(19); c.setCellStyle(cs2); c.setCellValue(children.get(rownum - 3).getOPV2()); c = r.createCell(20); c.setCellStyle(cs2); c.setCellValue(children.get(rownum - 3).getOPV3()); c = r.createCell(21); c.setCellStyle(cs2); c.setCellValue(children.get(rownum - 3).getMeasles1()); } FileOutputStream fileOut = new FileOutputStream(filePath); wb.write(fileOut); fileOut.close(); path = "/reports/" + prefixFileName + "_List_Children_Excel_" + currentTime + ".xls"; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return path; }
From source file:org.hil.children.service.impl.ChildrenManagerImpl.java
License:Open Source License
public String printListVaccinatedInLocationReport(String type, String timeFrom, String timeTo, Commune commune, District district, Vaccination vaccine, List<ChildrenVaccinatedInLocationVO> statistics) { SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); String path = ""; String prefixFileName = ""; if (commune != null) prefixFileName = district.getDistrictId() + "_" + commune.getCommuneId(); else if (district != null) prefixFileName = district.getDistrictId(); GraniteContext gc = GraniteContext.getCurrentInstance(); ServletContext sc = ((HttpGraniteContext) gc).getServletContext(); String reportDir = sc.getRealPath(config.getBaseReportDir()); long currentTime = System.currentTimeMillis(); String filePath = reportDir + "/" + prefixFileName + "_DanhSachTreDenTiem_" + vaccine.getName() + "_" + currentTime;//from www .j a va 2 s . c o m POIFSFileSystem fs; try { filePath += ".xls"; fs = new POIFSFileSystem( new FileInputStream(reportDir + "/excel/ListOfChildrenVaccinatedInLocation.xls")); HSSFWorkbook wb = new HSSFWorkbook(fs, true); HSSFSheet s = wb.getSheetAt(0); HSSFRow r = null; HSSFCell c = null; r = s.getRow(0); c = r.getCell(0); c.setCellValue("Danh sch tr n tim chng " + vaccine.getName() + " (bao gm c tr tim bnh vin/phng khm)"); r = s.getRow(1); c = r.getCell(1); c.setCellValue(district.getDistrictName()); if (commune != null) { c = r.getCell(2); c.setCellValue("X"); c = r.getCell(3); c.setCellValue(commune.getCommuneName()); c = r.getCell(4); c.setCellValue("(" + timeFrom + " - " + timeTo + ")"); } else { c = r.getCell(2); c.setCellValue("(" + timeFrom + " - " + timeTo + ")"); } HSSFCellStyle cs = wb.createCellStyle(); cs.setBorderBottom(HSSFCellStyle.BORDER_THIN); cs.setBorderTop(HSSFCellStyle.BORDER_THIN); cs.setBorderLeft(HSSFCellStyle.BORDER_THIN); cs.setBorderRight(HSSFCellStyle.BORDER_THIN); HSSFCellStyle cs1 = wb.createCellStyle(); cs1.setBorderBottom(HSSFCellStyle.BORDER_THIN); cs1.setBorderTop(HSSFCellStyle.BORDER_THIN); cs1.setBorderLeft(HSSFCellStyle.BORDER_THIN); cs1.setBorderRight(HSSFCellStyle.BORDER_THIN); cs1.setAlignment(HSSFCellStyle.ALIGN_CENTER); HSSFCellStyle cs2 = wb.createCellStyle(); cs2.setBorderBottom(HSSFCellStyle.BORDER_THIN); cs2.setBorderTop(HSSFCellStyle.BORDER_THIN); cs2.setBorderLeft(HSSFCellStyle.BORDER_THIN); cs2.setBorderRight(HSSFCellStyle.BORDER_THIN); CreationHelper createHelper = wb.getCreationHelper(); cs2.setDataFormat(createHelper.createDataFormat().getFormat("dd/MM/yyyy")); int rownum = 3; for (rownum = 3; rownum < statistics.size() + 3; rownum++) { r = s.createRow(rownum); c = r.createCell(0); c.setCellStyle(cs1); c.setCellValue(rownum - 2); c = r.createCell(1); c.setCellStyle(cs); c.setCellValue(statistics.get(rownum - 3).getCommuneName()); c = r.createCell(2); c.setCellStyle(cs); c.setCellValue(statistics.get(rownum - 3).getVillageName()); c = r.createCell(3); c.setCellStyle(cs); c.setCellValue(statistics.get(rownum - 3).getChildCode()); c = r.createCell(4); c.setCellStyle(cs); c.setCellValue(statistics.get(rownum - 3).getFullName()); c = r.createCell(5); c.setCellStyle(cs1); c.setCellValue(statistics.get(rownum - 3).getGender() == true ? "N" : "Nam"); c = r.createCell(6); c.setCellStyle(cs2); c.setCellValue(statistics.get(rownum - 3).getDateOfBirth()); c = r.createCell(7); c.setCellStyle(cs); c.setCellValue(statistics.get(rownum - 3).getMotherName()); c = r.createCell(8); c.setCellStyle(cs2); c.setCellValue(statistics.get(rownum - 3).getDateOfImmunization()); c = r.createCell(9); c.setCellStyle(cs); String vaccinatedLocation = ""; if (statistics.get(rownum - 3).getOtherLocation() != null && statistics.get(rownum - 3).getOtherLocation() >= 1 && statistics.get(rownum - 3).getOtherLocation() <= 4) { if (statistics.get(rownum - 3).getOtherLocation() == 1) vaccinatedLocation = "Bnh vin TW"; else if (statistics.get(rownum - 3).getOtherLocation() == 2) vaccinatedLocation = "Bnh vin tnh"; else if (statistics.get(rownum - 3).getOtherLocation() == 3) vaccinatedLocation = "Bnh vin huyn"; else if (statistics.get(rownum - 3).getOtherLocation() == 4) vaccinatedLocation = "Phng khm/Bnh vin t nhn"; } else vaccinatedLocation = statistics.get(rownum - 3).getVaccinatedCommune(); c.setCellValue(vaccinatedLocation); } FileOutputStream fileOut = new FileOutputStream(filePath); wb.write(fileOut); fileOut.close(); path = "/reports/" + prefixFileName + "_DanhSachTreDenTiem_" + vaccine.getName() + "_" + currentTime + ".xls"; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return path; }
From source file:org.jfree.workbook.io.XLWriter.java
License:Open Source License
/** * Creates a new cell in the HSSFRow, based on the contents of the supplied cell. * //from www .j a va 2s.co m * @param hssfWorkbook the workbook. * @param hssfRow the row. * @param worksheet the worksheet. * @param cell the cell. */ private void createHSSFCell(HSSFWorkbook hssfWorkbook, HSSFRow hssfRow, Worksheet worksheet, Cell cell) { HSSFCell hssfCell = hssfRow.createCell((short) cell.getColumn()); if (cell.getType() == Cell.LABEL_TYPE) { hssfCell.setCellType(HSSFCell.CELL_TYPE_STRING); hssfCell.setCellValue(cell.getContent()); } else if (cell.getType() == Cell.VALUE_TYPE) { hssfCell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); hssfCell.setCellValue(Double.valueOf(cell.getContent()).doubleValue()); } else if (cell.getType() == Cell.DATE_TYPE) { hssfCell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); hssfCell.setCellValue(Double.valueOf(cell.getContent()).doubleValue()); } HSSFCellStyle hssfStyle = hssfWorkbook.createCellStyle(); Style style = worksheet.getStyles().getStyle(cell.getRow(), cell.getColumn()); hssfStyle.setAlignment(getXLHorizontalAlignment(style)); hssfStyle.setVerticalAlignment(getXLVerticalAlignment(style)); hssfStyle.setWrapText(style.isWrapText()); //hssfStyle.setFillBackgroundColor(style.getBackgroundColor()); hssfStyle.setBorderTop(getXLBorder(style.getBorder().getTop())); hssfStyle.setBorderBottom(getXLBorder(style.getBorder().getBottom())); hssfStyle.setBorderLeft(getXLBorder(style.getBorder().getLeft())); hssfStyle.setBorderRight(getXLBorder(style.getBorder().getRight())); hssfCell.setCellStyle(hssfStyle); }