List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet createRow
@Override public HSSFRow createRow(int rownum)
From source file:com.photon.phresco.framework.commons.FrameworkUtil.java
License:Apache License
private void writeTestCaseToXLS(String testSuiteName, String[] cellValue, String status, int numCol, int cellno, CellStyle[] tryStyle, StringBuilder sb) throws PhrescoException { Iterator<Row> rowIterator; try {/*from ww w.j a va 2s .c o m*/ FileInputStream myInput = new FileInputStream(sb.toString()); HSSFWorkbook myWorkBook = new HSSFWorkbook(myInput); int numberOfSheets = myWorkBook.getNumberOfSheets(); for (int j = 0; j < numberOfSheets; j++) { HSSFSheet myHssfSheet = myWorkBook.getSheetAt(j); if (myHssfSheet.getSheetName().equals(testSuiteName)) { rowIterator = myHssfSheet.rowIterator(); Row next; for (Cell cell : myHssfSheet.getRow((myHssfSheet.getLastRowNum()) - 1)) { tryStyle[cellno] = cell.getCellStyle(); cellno = cellno + 1; if (cellno == 15) { break; } } float totalPass = 0; float totalFail = 0; float totalNotApp = 0; float totalBlocked = 0; float notExecuted = 0; float totalTestCases = 0; for (int i = 0; i <= 22; i++) { rowIterator.next(); } do { next = rowIterator.next(); if (StringUtils.isNotEmpty(getValue(next.getCell(1))) && !getValue(next.getCell(0)).equalsIgnoreCase("S.NO")) { String value = getValue(next.getCell(11)); if (StringUtils.isNotEmpty(value)) { if (value.equalsIgnoreCase("success")) { totalPass = totalPass + 1; } else if (value.equalsIgnoreCase("failure")) { totalFail = totalFail + 1; } else if (value.equalsIgnoreCase("notApplicable")) { totalNotApp = totalNotApp + 1; } else if (value.equalsIgnoreCase("blocked")) { totalBlocked = totalBlocked + 1; } } else { notExecuted = notExecuted + 1; } } } while (rowIterator.hasNext()); //to update the status in the index page if (status.equalsIgnoreCase("success")) { totalPass = totalPass + 1; } else if (status.equalsIgnoreCase("failure")) { totalFail = totalFail + 1; } else if (status.equalsIgnoreCase("notApplicable")) { totalNotApp = totalNotApp + 1; } else if (status.equalsIgnoreCase("blocked")) { totalBlocked = totalBlocked + 1; } else { notExecuted = notExecuted + 1; } totalTestCases = totalPass + totalFail + totalNotApp + totalBlocked + notExecuted; HSSFSheet mySheetHssf = myWorkBook.getSheetAt(0); rowIterator = mySheetHssf.rowIterator(); for (int i = 0; i <= 2; i++) { rowIterator.next(); } while (rowIterator.hasNext()) { Row next1 = rowIterator.next(); if (StringUtils.isNotEmpty(getValue(next1.getCell(2))) && !getValue(next1.getCell(2)).equalsIgnoreCase("Total")) { TestSuite createObject = createObject(next1); if (createObject.getName().equals(testSuiteName)) { addCalculationsToIndex(totalPass, totalFail, totalNotApp, totalBlocked, notExecuted, totalTestCases, next1); } } } Row r = null; if (myHssfSheet.getSheetName().equalsIgnoreCase("Index")) { r = myHssfSheet.createRow(next.getRowNum() - 1); } else { r = myHssfSheet.createRow(next.getRowNum() + 1); } for (int i = 0; i < numCol; i++) { Cell cell = r.createCell(i); cell.setCellValue(cellValue[i]); if (tryStyle[i] != null) { cell.setCellStyle(tryStyle[i]); } } FileOutputStream fileOut = new FileOutputStream(sb.toString()); myWorkBook.write(fileOut); myInput.close(); fileOut.close(); } } } catch (PhrescoException e) { throw new PhrescoException(e); } catch (FileNotFoundException e) { throw new PhrescoException(e); } catch (IOException e) { throw new PhrescoException(e); } }
From source file:com.project.jsica.cdi.ReporteBean.java
public void reporte2(List<ReportePermisoBean> reporte) { LOG.info("TAMAO reporte: " + reporte.size()); FacesContext fc = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse(); HSSFWorkbook libro = new HSSFWorkbook(); HSSFFont fuente = libro.createFont(); fuente.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); HSSFCellStyle estiloCeldaCabecera = libro.createCellStyle(); estiloCeldaCabecera.setFont(fuente); estiloCeldaCabecera.setAlignment(HSSFCellStyle.ALIGN_CENTER); DataFormat format = libro.createDataFormat(); HSSFCellStyle style = libro.createCellStyle(); style.setDataFormat(format.getFormat("hh:mm:ss")); HSSFCellStyle fechas = libro.createCellStyle(); fechas.setDataFormat(format.getFormat("dd.MM.yyyy")); HSSFSheet hoja = libro.createSheet("hoja 1"); //CREAR LAS CABECERAS String[] cabeceras = { "CODIGO", "NOMBRE", "HORA INICIO", "HORA FIN", "HORAS", "MINUTOS", "FECHA", "MOTIVO" }; HSSFRow filaCabecera = hoja.createRow(0); for (int x = 0; x < cabeceras.length; x++) { HSSFCell cabecera = filaCabecera.createCell(x); cabecera.setCellValue(cabeceras[x]); cabecera.setCellStyle(estiloCeldaCabecera); }/*from w w w . j ava 2 s .co m*/ //FIN DE CABECERAS for (int i = 0; i < reporte.size(); i++) { HSSFRow fila = hoja.createRow(i + 1); HSSFCell columna1 = fila.createCell(0); columna1.setCellValue(reporte.get(i).getCodigo()); HSSFCell columna2 = fila.createCell(1); columna2.setCellValue(reporte.get(i).getNombre()); HSSFCell columna3 = fila.createCell(2); columna3.setCellValue(reporte.get(i).getHoraInicio()); columna3.setCellStyle(style); HSSFCell columna4 = fila.createCell(3); columna4.setCellValue(reporte.get(i).getHoraFin()); columna4.setCellStyle(style); HSSFCell columna5 = fila.createCell(4); columna5.setCellValue(reporte.get(i).getHoras()); HSSFCell columna6 = fila.createCell(5); columna6.setCellValue(reporte.get(i).getMinutos()); HSSFCell columna7 = fila.createCell(6); columna7.setCellValue(reporte.get(i).getFechaReal()); columna7.setCellStyle(fechas); HSSFCell columna8 = fila.createCell(7); columna8.setCellValue(reporte.get(i).getMotivo()); } try { OutputStream output = response.getOutputStream(); libro.write(output); output.close(); fc.responseComplete(); } catch (IOException ex) { LOG.info("ERROR: " + ex); } }
From source file:com.project.jsica.cdi.ReporteBean.java
public void reporte3() { if (nuevoReporte) { LOG.info("OPCION: " + opcionReporte); String nombreReporte = ""; int filas = 0; if (opcionReporte == 2) { reporte = registroAsistenciaController.buscarXArea(areaSeleccionada, desde, hasta); LOG.info("TAMAO reporte: " + reporte.size()); nombreReporte = "Reporte de asistencia por area"; filas = 1;// ww w . ja va 2 s . co m } else if (opcionReporte == 1) { reporte = registroAsistenciaController.buscarXEmpleado(empleado, desde, hasta); LOG.info("TAMAO reporte: " + reporte.size()); nombreReporte = "Reporte de asistencia por empleado"; filas = 0; } FacesContext fc = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse(); response.reset(); response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-Disposition", "attachment; filename=" + nombreReporte + ".xls"); HSSFWorkbook libro = new HSSFWorkbook(); HSSFFont fuente = libro.createFont(); fuente.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); HSSFCellStyle estiloCeldaCabecera = libro.createCellStyle(); estiloCeldaCabecera.setFont(fuente); estiloCeldaCabecera.setAlignment(HSSFCellStyle.ALIGN_CENTER); DataFormat format = libro.createDataFormat(); HSSFCellStyle style = libro.createCellStyle(); style.setDataFormat(format.getFormat("hh:mm:ss")); HSSFCellStyle fechas = libro.createCellStyle(); fechas.setDataFormat(format.getFormat("dd.MM.yyyy")); HSSFSheet hoja = libro.createSheet("Reporte de Asistencias"); //CREAR LAS CABECERAS String[] cabeceras = { "CODIGO", "APELLIDOS Y NOMBRES", "FECHA", "TIPO", "HORA DE INGRESO", "HORA DE SALIDA", "MARCACION DE ENTRADA", "MARCACION DE SALIDA", "TARDANZA(Minutos)", "SALIDA REFRIGERIO", "ENTRADA REFRIGERIO", "MARCACION SALIDA R", "MARCACION DE ENTRADA R", "TARDANZA(refrigerio)", "TARDANZA TOTAL" }; if (filas == 1) { HSSFRow filaArea = hoja.createRow(0); HSSFCell Area = filaArea.createCell(0); Area.setCellValue("AREA"); Area.setCellStyle(estiloCeldaCabecera); HSSFCell nombre = filaArea.createCell(1); nombre.setCellValue(areaSeleccionada.getNombre() + ""); } HSSFRow filaCabecera = hoja.createRow(filas); for (int x = 0; x < cabeceras.length; x++) { HSSFCell cabecera = filaCabecera.createCell(x); cabecera.setCellValue(cabeceras[x]); cabecera.setCellStyle(estiloCeldaCabecera); } //FIN DE CABECERAS for (int i = filas; i < reporte.size(); i++) { HSSFRow fila = hoja.createRow(i + 1); HSSFCell columna1 = fila.createCell(0); columna1.setCellValue(reporte.get(i).getEmpleado().getCodigo()); HSSFCell columna2 = fila.createCell(1); columna2.setCellValue(reporte.get(i).getEmpleado().getNombreCompleto()); HSSFCell columna3 = fila.createCell(2); columna3.setCellValue(reporte.get(i).getFecha()); columna3.setCellStyle(fechas); HSSFCell columna4 = fila.createCell(3); columna4.setCellValue(reporte.get(i).getTipo() + ""); HSSFCell columna5 = fila.createCell(4); columna5.setCellValue(reporte.get(i).getHoraEntrada()); columna5.setCellStyle(style); HSSFCell columna6 = fila.createCell(5); columna6.setCellValue(reporte.get(i).getHoraSalida()); columna6.setCellStyle(style); HSSFCell columna7 = fila.createCell(6); if (reporte.get(i).getMarcacionInicio() != null) { columna7.setCellValue(reporte.get(i).getMarcacionInicio()); columna7.setCellStyle(style); } else { columna7.setCellValue("No marco."); } HSSFCell columna8 = fila.createCell(7); if (reporte.get(i).getMarcacionFin() != null) { columna8.setCellValue(reporte.get(i).getMarcacionFin()); columna8.setCellStyle(style); } else { columna8.setCellValue("No marco."); } HSSFCell columna9 = fila.createCell(8); int minutos = (int) ((reporte.get(i).getMilisTardanzaTotal() / (1000 * 60)) % 60); columna9.setCellValue(minutos); HSSFCell columna10 = fila.createCell(9); columna10.setCellValue(reporte.get(i).getHoraSalidaRefrigerio()); columna10.setCellStyle(style); HSSFCell columna11 = fila.createCell(10); columna11.setCellValue(reporte.get(i).getHoraEntradaRefrigerio()); columna11.setCellStyle(style); HSSFCell columna12 = fila.createCell(11); if (reporte.get(i).getMarcacionInicioRefrigerio() != null) { columna12.setCellValue(reporte.get(i).getMarcacionInicioRefrigerio()); columna12.setCellStyle(style); } else { columna12.setCellValue("No marco."); } HSSFCell columna13 = fila.createCell(12); if (reporte.get(i).getMarcacionFinRefrigerio() != null) { columna13.setCellValue(reporte.get(i).getMarcacionFinRefrigerio()); columna13.setCellStyle(style); } else { columna13.setCellValue("No marco."); } HSSFCell columna14 = fila.createCell(13); columna14.setCellValue((int) ((reporte.get(i).getMilisTardanzaRefrigerio() / (1000 * 60)) % 60)); HSSFCell columna15 = fila.createCell(14); columna15.setCellValue((int) ((reporte.get(i).getMilisTardanzaTotalFinal() / (1000 * 60)) % 60)); } try { OutputStream output = response.getOutputStream(); libro.write(output); output.close(); fc.responseComplete(); } catch (IOException ex) { LOG.info("ERROR: " + ex); } nuevoReporte = false; } }
From source file:com.pureinfo.dolphin.export.impl.ExcelExporterImpl.java
License:Open Source License
/** * Exports headers to excel./*from w w w . j av a2s . c o m*/ * * @param _sheet * excel work sheet * @param _headers * header titles */ public static void exportHeaders(HSSFSheet _sheet, String _headers[], HSSFCellStyle _headStyle) throws PureException { HSSFRow row = _sheet.createRow(0); for (short j = 0; j < _headers.length; j++) { _sheet.setColumnWidth(j, (short) 3000); HSSFCell cell = row.createCell(j); cell.setEncoding((short) 1); cell.setCellStyle(_headStyle); cell.setCellValue(_headers[j]); } }
From source file:com.pureinfo.dolphin.export.impl.ExcelExporterImpl.java
License:Open Source License
/** * Exports a row to excel.//from w ww .j a va 2 s . c o m * * @param _sheet * excel work sheet * @param _cols * columns values * @param _nRowNum * row number * @param _dateStyle * date style * @throws PureException * if failed. */ public static void exportRow(HSSFSheet _sheet, Object[] _cols, int _nRowNum, HSSFCellStyle _dateStyle) throws PureException { HSSFCell cell; Object value; HSSFRow row = _sheet.createRow(_nRowNum); for (short nCol = 0; nCol < _cols.length; nCol++) { _sheet.setColumnWidth(nCol, (short) 3000); cell = row.createCell(nCol); cell.setEncoding((short) 1); value = _cols[nCol]; if (value == null) { cell.setCellValue(""); } else if (value instanceof String) { cell.setCellValue((String) value); } else if (value instanceof Number) { cell.setCellValue(((Number) value).doubleValue()); } else if (value instanceof Boolean) { cell.setCellValue(((Boolean) value).booleanValue()); } else if (value instanceof Date) { cell.setCellStyle(_dateStyle); cell.setCellValue((Date) value); } else if (value instanceof Calendar) { cell.setCellStyle(_dateStyle); cell.setCellValue((Calendar) value); } else { cell.setCellValue(value.toString()); } } }
From source file:com.pureinfo.srm.project.model.compile.helper.CompileExcelExportHelper.java
License:Open Source License
public static void exportRow(HSSFSheet _sheet, Object[] _cols, int _nRowNum, HSSFCellStyle _dateStyle, HSSFCellStyle _doubleStyle) throws PureException { HSSFCell cell;/*from w ww .ja va 2 s . com*/ Object value; HSSFRow row = _sheet.createRow(_nRowNum); for (short nCol = 0; nCol < _cols.length; nCol++) { _sheet.setColumnWidth(nCol, (short) 3000); cell = row.createCell(nCol); cell.setEncoding((short) 1); value = _cols[nCol]; if (value == null) { cell.setCellValue(""); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); cell.setCellStyle(style); } else if (value instanceof String) { cell.setCellValue((String) value); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); cell.setCellStyle(style); } else if (value instanceof Number) { cell.setCellValue(((Number) value).doubleValue()); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); cell.setCellStyle(_doubleStyle); } else if (value instanceof Boolean) { cell.setCellValue(((Boolean) value).booleanValue()); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); cell.setCellStyle(style); } else if (value instanceof Date) { cell.setCellValue((Date) value); cell.setCellStyle(_dateStyle); } else if (value instanceof Calendar) { cell.setCellValue((Calendar) value); cell.setCellStyle(_dateStyle); } else { cell.setCellValue(value.toString()); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); cell.setCellStyle(style); } } }
From source file:com.pureinfo.srm.project.model.compile.helper.CompileExcelExportHelper.java
License:Open Source License
public static void exportHeaders(HSSFSheet _sheet, String _headers[], HSSFCellStyle _headStyle) throws PureException { HSSFRow row = _sheet.createRow(0); for (short j = 0; j < _headers.length; j++) { _sheet.setColumnWidth(j, (short) 3000); HSSFCell cell = row.createCell(j); cell.setEncoding((short) 1); cell.setCellValue(_headers[j]);//from www. j av a 2 s. c o m cell.setCellStyle(_headStyle); } }
From source file:com.qcadoo.mes.assignmentToShift.print.xls.AssignmentToShiftXlsService.java
License:Open Source License
private void createHeaderForAuthor(final HSSFSheet sheet, final Locale locale, final Entity entity) { HSSFRow headerAuthorLine = sheet.createRow(1); String shift = translationService.translate(COLUMN_HEADER_SHIFT, locale) + " " + entity.getBelongsToField(SHIFT).getStringField(NAME); String user = translationService.translate(COLUMN_HEADER_AUTHOR, locale) + " " + entity.getField(CREATE_USER).toString(); String date = translationService.translate(COLUMN_HEADER_UPDATE_DATE, locale) + " " + DateFormat.getDateInstance().format(entity.getField(UPDATE_DATE)); HSSFCell cellAuthorLine0 = headerAuthorLine.createCell(0); cellAuthorLine0.setCellValue(shift); HSSFCell cellAuthorLine3 = headerAuthorLine.createCell(3); cellAuthorLine3.setCellValue(date);//from ww w . j a v a 2 s . c o m HSSFCell cellAuthorLine6 = headerAuthorLine.createCell(6); cellAuthorLine6.setCellValue(user); headerAuthorLine.setHeightInPoints(30); assignmentToShiftXlsStyleHelper.addMarginsAndStylesForAuthor(sheet, 1, assignmentToShiftXlsHelper.getNumberOfDaysBetweenGivenDates(entity)); }
From source file:com.qcadoo.mes.assignmentToShift.print.xls.AssignmentToShiftXlsService.java
License:Open Source License
private void createHeaderForAssignmentToShift(final HSSFSheet sheet, final Locale locale, final Entity entity) { List<DateTime> days = assignmentToShiftXlsHelper.getDaysBetweenGivenDates(entity); if (days != null) { HSSFRow headerAssignmentToShift = sheet.createRow(3); String occupationType = translationService.translate(COLUMN_HEADER_OCCUPATIONTYPE, locale); HSSFCell cell0 = headerAssignmentToShift.createCell(0); cell0.setCellValue(occupationType); int columnNumber = 1; for (DateTime day : days) { HSSFCell cellDay = headerAssignmentToShift.createCell(columnNumber); cellDay.setCellValue(translationService.translate(COLUMN_HEADER_DAY, locale, DateFormat.getDateInstance().format(new Date(day.getMillis())))); columnNumber += 3;//from w w w. jav a2s .c o m } headerAssignmentToShift.setHeightInPoints(14); assignmentToShiftXlsStyleHelper.addMarginsAndStylesForAssignmentToShift(sheet, 3, assignmentToShiftXlsHelper.getNumberOfDaysBetweenGivenDates(entity)); } }
From source file:com.qcadoo.mes.assignmentToShift.print.xls.AssignmentToShiftXlsService.java
License:Open Source License
private int fillColumnWithStaffForWorkOnLine(final HSSFSheet sheet, int rowNum, final Entity assignmentToShiftReport, final List<DateTime> days, final List<Entity> productionLines, final Entity dictionaryItem) { if ((assignmentToShiftReport != null) && (days != null) && (productionLines != null)) { for (Entity productionLine : productionLines) { int rowNumFromLastSection = rowNum; int numberOfColumnsForWorkers = getNumberOfRowsForWorkers(assignmentToShiftReport, days, productionLine, dictionaryItem); for (int i = 0; i < numberOfColumnsForWorkers; i++) { HSSFRow row = sheet.createRow(rowNum); rowNum++;/*ww w .j a v a2 s . co m*/ } String productionLineValue = null; if (productionLine.getStringField(PLACE) == null) { productionLineValue = productionLine.getStringField(NUMBER); } else { productionLineValue = productionLine.getStringField(NUMBER) + "-" + productionLine.getStringField(ProductionLineFields.PLACE); } HSSFRow firstRowInSection = null; if (sheet.getRow(rowNumFromLastSection) == null) { firstRowInSection = sheet.createRow(rowNumFromLastSection); rowNum++; } else { firstRowInSection = sheet.getRow(rowNumFromLastSection); } HSSFCell cell = firstRowInSection.createCell(0); cell.setCellValue(productionLineValue); sheet.addMergedRegion(new CellRangeAddress(rowNumFromLastSection, rowNum - 1, 0, 0)); int columnNumber = 1; int maxLength = 0; for (DateTime day : days) { Entity assignmentToShift = assignmentToShiftXlsHelper .getAssignmentToShift(assignmentToShiftReport.getBelongsToField(SHIFT), day.toDate()); if (assignmentToShift == null) { columnNumber += 3; continue; } List<Entity> staffs = assignmentToShiftXlsHelper.getStaffsList(assignmentToShift, dictionaryItem.getStringField(NAME), productionLine); if (staffs.isEmpty()) { columnNumber += 3; continue; } String staffsValue = assignmentToShiftXlsHelper.getListOfWorkers(staffs); List<String> workers = assignmentToShiftXlsHelper.getListOfWorker(staffs); int rowIndex = rowNumFromLastSection; for (String worker : workers) { sheet.getRow(rowIndex).createCell(columnNumber).setCellValue(worker); rowIndex++; } if (workers.isEmpty()) { sheet.getRow(rowIndex).createCell(columnNumber).setCellValue(" "); } if (maxLength < staffsValue.length()) { maxLength = staffsValue.length(); } // row.setHeightInPoints(assignmentToShiftXlsStyleHelper.getHeightForRow(maxLength, 22, 14)); columnNumber += 3; } for (int i = rowNumFromLastSection; i < rowNum; i++) { assignmentToShiftXlsStyleHelper.addMarginsAndStylesForSeries(sheet, i, assignmentToShiftXlsHelper.getNumberOfDaysBetweenGivenDates(assignmentToShiftReport)); } } } return rowNum; }