List of usage examples for org.apache.poi.hssf.usermodel HSSFRow setHeight
@Override public void setHeight(short height)
From source file:mx.avanti.siract.ui.FiltrosBeanUI.java
public HSSFSheet cabezeraGeneralExcel(HSSFSheet sheet, int logouabc, HSSFCellStyle style) { /* Create the drawing container */ HSSFPatriarch drawing = sheet.createDrawingPatriarch(); /* Create an anchor point */ ClientAnchor my_anchor = new HSSFClientAnchor(); /* Define top left corner, and we can resize picture suitable from there */ my_anchor.setCol1(1);// w ww.j ava 2s. c o m my_anchor.setRow1(1); /* Invoke createPicture and pass the anchor point and ID */ HSSFPicture my_picture = drawing.createPicture(my_anchor, logouabc); /* Call resize method, which resizes the image */ double escalaRes = 1; my_picture.resize(escalaRes); //definiremos el estilo para estas Celdas //Definiremos el nombre de la escuela HSSFRow row = sheet.createRow(2); row.setHeight((short) 600); HSSFCell cell = row.createCell(3); cell.setCellValue("Universidad Autnoma de Baja California"); cell.setCellStyle(style); row = sheet.createRow(3); row.setHeight((short) 600); cell = row.createCell(3); cell.setCellValue("Facultad de Ingeniera"); cell.setCellStyle(style); row = sheet.createRow(4); row.setHeight((short) 600); cell = row.createCell(3); cell.setCellValue("Mexicali"); cell.setCellStyle(style); return sheet; }
From source file:net.chaosserver.timelord.data.ExcelDataReaderWriter.java
License:Open Source License
/** * Generates the actual workbook of data. * * @param timelordData the data to generate a workbook for * @return the workbook/*from w w w . j a v a 2 s . c o m*/ */ protected HSSFWorkbook generateWorkbook(TimelordData timelordData) { HSSFWorkbook wb = new HSSFWorkbook(); // Build the Map of the Styles that will be applied to cells // in the workbook Map<String, HSSFCellStyle> styleMap = buildStyleMap(wb); Map<String, List<String>> sheetToNotes = new TreeMap<String, List<String>>(new DateComparator()); // Since there is an issue re-ordering sheets after they // have been created. First create the book with all needed // sheets preCreateAllSheets(wb, timelordData, sheetToNotes, styleMap); // After all the sheets have been pre-created, iterate through all // the tasks to add them into the sheets. int rowNum = addAllTasks(wb, timelordData, sheetToNotes, styleMap); // This section applies all the styles, creates the footers and adds // the notes onto the sheet. for (int i = 0; i < wb.getNumberOfSheets(); i++) { HSSFSheet sheet = wb.getSheetAt(i); String sheetName = wb.getSheetName(i); createFooterRows(sheet, rowNum, styleMap); // This will apply styles to the rows that had no task associated // for a given week. for (int j = 1; j < rowNum - 1; j++) { HSSFRow row = sheet.getRow(j); if (row == null) { row = sheet.createRow(j); row.setHeight((short) 0); HSSFCell cell = row.createCell((short) 0); cell.setCellStyle((HSSFCellStyle) styleMap.get("taskNameStyle")); cell.setCellValue(""); cell = row.createCell(MAX_COLUMN); cell.setCellStyle((HSSFCellStyle) styleMap.get("totalColumnStyle")); cell.setCellFormula("SUM(B" + (j + 1) + ":H" + (j + 1) + ")"); } } List<String> noteList = sheetToNotes.get(sheetName); createNotesRows(sheet, noteList); HSSFPrintSetup ps = sheet.getPrintSetup(); ps.setLandscape(true); } // Finally order the sheets properly if (logger.isDebugEnabled()) { logger.debug("Re-ordering sheets under final order."); } return wb; }
From source file:org.clickframes.plugins.requirements.Requirement.java
License:Open Source License
public static void renderSpreadsheet(List<Requirement> requirements, File xls) throws IOException { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet();/*from w w w.j a v a2 s . c om*/ HSSFCellStyle identifierStyle = RequirementsGenerator.createIdentifierColumnStyle(wb); HSSFCellStyle requirementStyle = RequirementsGenerator.createRequirementColumnStyle(wb); HSSFCellStyle prStyle = RequirementsGenerator.createRequirementColumnStyle(wb); HSSFCellStyle headerStyle = RequirementsGenerator.createHeaderColumnStyle(wb); short rowHeight = 480; short rowNo = 0; { // header HSSFRow row = sheet.createRow(rowNo++); row.setHeight(rowHeight); HSSFCell cell1 = row.createCell((short) 0); cell1.setCellValue(new HSSFRichTextString("Requirement Identifier")); cell1.setCellStyle(headerStyle); HSSFCell cell2 = row.createCell((short) 1); cell2.setCellValue(new HSSFRichTextString("Software Requirement")); cell2.setCellStyle(headerStyle); HSSFCell cell3 = row.createCell((short) 2); cell3.setCellValue(new HSSFRichTextString("Product Requirement")); cell3.setCellStyle(headerStyle); } rowNo++; for (Requirement requirement : requirements) { HSSFRow row = sheet.createRow(rowNo++); row.setHeight(rowHeight); HSSFCell identifierCell = row.createCell((short) 0); identifierCell.setCellValue(new HSSFRichTextString(requirement.getIdentifier())); identifierCell.setCellStyle(identifierStyle); HSSFCell requirementCell = row.createCell((short) 1); requirementCell.setCellValue(new HSSFRichTextString(requirement.getTitle())); requirementCell.setCellStyle(requirementStyle); if (requirement.getPage() != null) { String pr = requirement.getPage().getProperties().get("pr"); HSSFCell prCell = row.createCell((short) 2); prCell.setCellValue(new HSSFRichTextString(pr)); prCell.setCellStyle(prStyle); } } sheet.autoSizeColumn((short) 0); sheet.autoSizeColumn((short) 1); wb.write(new FileOutputStream(xls)); }
From source file:org.forzaframework.util.XlsUtils.java
License:Apache License
public static void setRowHeight(HSSFSheet sheet, Integer row, Short height) { HSSFRow headerRow = sheet.getRow(row); if (headerRow != null) { headerRow.setHeight(height); }/*from w w w.j a v a 2s . c o m*/ }
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//from w ww .j av a 2 s .co 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.jxstar.report.util.ReportXlsUtil.java
/** * ?PageSize?/*from w w w .j av a 2s . c o m*/ * @param sheet -- ? * @param startRow -- ???PageSize * @param rows -- ? * @return */ public static HSSFSheet insertSheetRow(HSSFSheet sheet, int startRow, int rows) { if (sheet == null) return null; sheet.shiftRows(startRow, sheet.getLastRowNum(), rows, true, false); HSSFCell sourcell = null, descell = null; HSSFRow sourow = sheet.getRow(startRow - 1); for (int i = 0; i < rows; i++) { HSSFRow descrow = sheet.createRow(startRow + i); descrow.setHeight(sourow.getHeight()); descrow.setHeightInPoints(sourow.getHeightInPoints()); java.util.Iterator<Cell> iter = sourow.cellIterator(); while (iter.hasNext()) { sourcell = (HSSFCell) iter.next(); int column = sourcell.getColumnIndex(); descell = descrow.createCell(column); descell.setCellType(sourcell.getCellType()); descell.setCellStyle(sourcell.getCellStyle()); } } //?? insertSheetRegions(sheet, startRow, rows); return sheet; }
From source file:org.ofbiz.webtools.ExcelConversionFilter.java
License:Open Source License
void applyStylesToSheet(Map<String, ? extends Object> context, HSSFWorkbook workBook, HSSFSheet sheet, ServletRequest request) {// w w w .j a v a 2 s .c om List headerKeys = new ArrayList(); int noOfheads = 0; headerKeys = UtilMisc.toList("mainHeader1", "mainHeader2", "mainHeader3", "mainHeader4", "mainHeader5"); Map<String, Object> stylesMap = FastMap.newInstance(); stylesMap = (Map) context.get("stylesMap"); ArrayList allRowAndColData = (ArrayList) context.get("allRowAndColData"); Integer mainHeadingCell = 5; Integer mainHeadercellHeight = null; String mainHeaderFontName = null; Integer mainHeaderFontSize = null; Boolean mainHeaderBold = true; Integer columnHeaderCellHeight = null; Boolean columnHeaderBold = true; Boolean columnHeaderBgColor = null; String columnHeaderFontName = null; Boolean autoSizeCell = true; Integer columnHeaderFontSize = null; mainHeadercellHeight = (Integer) stylesMap.get("mainHeadercellHeight"); mainHeaderFontName = (String) stylesMap.get("mainHeaderFontName"); mainHeaderFontSize = (Integer) stylesMap.get("mainHeaderFontSize"); if (stylesMap.get("mainHeaderBold") != null) { mainHeaderBold = (Boolean) stylesMap.get("mainHeaderBold"); } if (stylesMap.get("columnHeaderBold") != null) { columnHeaderBold = (Boolean) stylesMap.get("columnHeaderBold"); } if (stylesMap.get("autoSizeCell") != null) { autoSizeCell = (Boolean) stylesMap.get("autoSizeCell"); } if (stylesMap.get("mainHeadingCell") != null) { mainHeadingCell = (Integer) stylesMap.get("mainHeadingCell"); } columnHeaderCellHeight = (Integer) stylesMap.get("columnHeaderCellHeight"); columnHeaderBgColor = (Boolean) stylesMap.get("columnHeaderBgColor"); columnHeaderFontName = (String) stylesMap.get("columnHeaderFontName"); columnHeaderFontSize = (Integer) stylesMap.get("columnHeaderFontSize"); ArrayList styles = new ArrayList(stylesMap.keySet()); for (int i = 0; i < styles.size(); i++) { ArrayList tempArrayList = new ArrayList<String>(); if (headerKeys.contains(styles.get(i))) { ArrayList<?> innerData = (ArrayList<?>) allRowAndColData.get(i); tempArrayList.add(stylesMap.get(styles.get(i))); for (int j = 0; j < innerData.size() - 1; j++) { tempArrayList.add(""); } allRowAndColData.add(i, tempArrayList); ++noOfheads; } } try { for (int i = 0; i < allRowAndColData.size(); i++) { HSSFCellStyle style = workBook.createCellStyle(); HSSFFont font = workBook.createFont(); ArrayList<?> ardata = (ArrayList<?>) allRowAndColData.get(i); HSSFRow row = sheet.createRow(i); for (int k = 0; k < ardata.size(); k++) { HSSFCell cell = row.createCell(k); if (k == mainHeadingCell && i <= noOfheads) { if (UtilValidate.isNotEmpty(mainHeadercellHeight)) { row.setHeight((short) mainHeadercellHeight.shortValue()); } else { row.setHeight((short) 400); } if (UtilValidate.isNotEmpty(mainHeaderFontName)) { font.setFontName(mainHeaderFontName); } if (UtilValidate.isNotEmpty(mainHeaderBold) && mainHeaderBold) { font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); } if (UtilValidate.isNotEmpty(mainHeaderFontSize)) { font.setFontHeightInPoints((short) mainHeaderFontSize.shortValue()); } else { font.setFontHeightInPoints((short) 12); //default value } style.setAlignment(HSSFCellStyle.ALIGN_CENTER); style.setFont(font); cell.setCellValue((ardata.get(0).toString()).replaceAll("\"", "")); cell.setCellStyle(style); } else if (i == noOfheads + 1) { if (UtilValidate.isNotEmpty(columnHeaderCellHeight)) { row.setHeight((short) columnHeaderCellHeight.shortValue()); } else { row.setHeight((short) 300); } if (UtilValidate.isNotEmpty(columnHeaderBold) && columnHeaderBold) { font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); } if (UtilValidate.isNotEmpty(columnHeaderFontSize)) { font.setFontHeightInPoints((short) columnHeaderFontSize.shortValue()); } else { font.setFontHeightInPoints((short) 9); } if (UtilValidate.isNotEmpty(columnHeaderFontName)) { font.setFontName(columnHeaderFontName); } if (UtilValidate.isNotEmpty(columnHeaderBgColor) && columnHeaderBgColor) { style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); } style.setAlignment(HSSFCellStyle.ALIGN_CENTER); style.setFont(font); cell.setCellValue((ardata.get(k).toString()).replaceAll("\"", "")); cell.setCellStyle(style); } else if (i > noOfheads) { cell.setCellValue((ardata.get(k).toString()).replaceAll("\"", "")); } if (UtilValidate.isNotEmpty(autoSizeCell) && autoSizeCell) { sheet.autoSizeColumn(k); } } } } catch (Exception e) { Debug.logInfo(e.getMessage(), module); request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); } }
From source file:org.openmicroscopy.shoola.util.file.SheetInfo.java
License:Open Source License
/** * Sets the height of the row rowIndex to rowHeight in pixels. * /*from w w w. ja v a 2s . co m*/ * @param rowIndex The index of the row. * @param rowHeight The height of the row. */ void setRowHeight(int rowIndex, int rowHeight) { HSSFRow row = sheet.getRow(rowIndex); if (row == null) row = sheet.createRow(rowIndex); row.setHeight((short) rowHeight); }
From source file:org.openmrs.module.kenyaemr.export.ExportLayouter.java
License:Open Source License
/** * Builds the report title and the date header * //from w ww . j av a 2 s .co m * @param worksheet * @param startRowIndex * starting row offset * @param startColIndex * starting column offset */ public static void buildTitle(HSSFSheet worksheet, int startRowIndex, int startColIndex) { // Create font style for the report title Font fontTitle = worksheet.getWorkbook().createFont(); fontTitle.setBoldweight(Font.BOLDWEIGHT_BOLD); fontTitle.setFontHeight((short) 280); // Create cell style for the report title HSSFCellStyle cellStyleTitle = worksheet.getWorkbook().createCellStyle(); cellStyleTitle.setAlignment(CellStyle.ALIGN_CENTER); cellStyleTitle.setWrapText(true); cellStyleTitle.setFont(fontTitle); // Create report title HSSFRow rowTitle = worksheet.createRow((short) startRowIndex); rowTitle.setHeight((short) 500); HSSFCell cellTitle = rowTitle.createCell(startColIndex); cellTitle.setCellValue("Patient Lab Result Report"); cellTitle.setCellStyle(cellStyleTitle); // Create merged region for the report title worksheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 9)); // Create date header HSSFRow dateTitle = worksheet.createRow((short) startRowIndex + 1); HSSFCell cellDate = dateTitle.createCell(startColIndex); //ghanshyam 27-sept-2012 Support #393 [Laboratory]Export to Excel option in print worklist (note: changed day,date and time format inside excel report sheet) String months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; String days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; GregorianCalendar gcalendar = new GregorianCalendar(); String dayName = days[gcalendar.get(Calendar.DAY_OF_WEEK) - 1]; String date = (gcalendar.get(Calendar.DATE) + "-" + months[gcalendar.get(Calendar.MONTH)] + "-" + gcalendar.get(Calendar.YEAR)).toString(); Date d = new Date(); cellDate.setCellValue("This report was generated on " + dayName + " " + date + " " + "at" + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds()); }
From source file:org.openmrs.module.kenyaemr.export.ExportLayouter.java
License:Open Source License
/** * Builds the column headers//from w w w . j a v a 2s . c o m * * @param worksheet * @param startRowIndex * starting row offset * @param startColIndex * starting column offset */ public static void buildHeaders(HSSFSheet worksheet, int startRowIndex, int startColIndex) { // Create font style for the headers Font font = worksheet.getWorkbook().createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); // Create cell style for the headers HSSFCellStyle headerCellStyle = worksheet.getWorkbook().createCellStyle(); headerCellStyle.setFillBackgroundColor(HSSFColor.GREY_25_PERCENT.index); headerCellStyle.setFillPattern(CellStyle.FINE_DOTS); headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER); headerCellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); headerCellStyle.setWrapText(true); headerCellStyle.setFont(font); headerCellStyle.setBorderBottom(CellStyle.BORDER_THIN); // Create the column headers HSSFRow rowHeader = worksheet.createRow((short) startRowIndex + 2); rowHeader.setHeight((short) 500); HSSFCell cell1 = rowHeader.createCell(startColIndex + 0); cell1.setCellValue("Order Date"); cell1.setCellStyle(headerCellStyle); HSSFCell cell2 = rowHeader.createCell(startColIndex + 1); cell2.setCellValue("Patient Identifier"); cell2.setCellStyle(headerCellStyle); HSSFCell cell3 = rowHeader.createCell(startColIndex + 2); cell3.setCellValue("Name"); cell3.setCellStyle(headerCellStyle); HSSFCell cell4 = rowHeader.createCell(startColIndex + 3); cell4.setCellValue("Age"); cell4.setCellStyle(headerCellStyle); HSSFCell cell5 = rowHeader.createCell(startColIndex + 4); cell5.setCellValue("Gender"); cell5.setCellStyle(headerCellStyle); HSSFCell cell6 = rowHeader.createCell(startColIndex + 5); cell6.setCellValue("Sample No."); cell6.setCellStyle(headerCellStyle); HSSFCell cell7 = rowHeader.createCell(startColIndex + 6); cell7.setCellValue("Lab"); cell7.setCellStyle(headerCellStyle); HSSFCell cell8 = rowHeader.createCell(startColIndex + 7); cell8.setCellValue("Test"); cell8.setCellStyle(headerCellStyle); HSSFCell cell9 = rowHeader.createCell(startColIndex + 8); cell9.setCellValue("Test name"); cell9.setCellStyle(headerCellStyle); HSSFCell cell10 = rowHeader.createCell(startColIndex + 9); cell10.setCellValue("Result"); cell10.setCellStyle(headerCellStyle); }