List of usage examples for org.apache.poi.hssf.usermodel HSSFWorkbook createFont
@Override
public HSSFFont createFont()
From source file:com.primovision.lutransport.core.util.TollCompanyTagUploadUtil.java
public static ByteArrayOutputStream createTollUploadErrorResponse(InputStream is, List<String> errors) throws IOException { POIFSFileSystem fs = new POIFSFileSystem(is); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFFont font = wb.createFont(); font.setColor(Font.COLOR_RED); font.setBoldweight(Font.BOLDWEIGHT_BOLD); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setFont(font);/* w w w . j av a2 s .co m*/ HSSFSheet sheet = wb.getSheetAt(0); Row row = sheet.getRow(0); int lastCell = row.getLastCellNum(); Cell cell = createExcelCell(sheet, row, lastCell, 256 * 100); cell.setCellStyle(cellStyle); cell.setCellValue("ERRORS"); for (String anError : errors) { String lineNoStr = StringUtils.substringBefore(anError, ":"); lineNoStr = StringUtils.substringAfter(lineNoStr, "Line "); Integer lineNo = new Integer(lineNoStr) - 1; row = sheet.getRow(lineNo); cell = createExcelCell(sheet, row, lastCell, 256 * 100); cell.setCellStyle(cellStyle); cell.setCellValue(anError); } return createOutputStream(wb); }
From source file:com.primovision.lutransport.core.util.TollCompanyTagUploadUtil.java
public static ByteArrayOutputStream createTollUploadSuccessResponse() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFFont font = wb.createFont(); font.setColor(IndexedColors.GREEN.getIndex()); font.setBoldweight(Font.BOLDWEIGHT_BOLD); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setFont(font);//from w w w. j a v a 2 s.co m Sheet sheet = wb.createSheet(); Row row = sheet.createRow(0); Cell cell = createExcelCell(sheet, row, 0, 256 * 100); cell.setCellStyle(cellStyle); cell.setCellValue("ALL tolls uploaded successfully"); return createOutputStream(wb); }
From source file:com.primovision.lutransport.core.util.TollCompanyTagUploadUtil.java
public static ByteArrayOutputStream createTollUploadExceptionResponse(Exception e) { HSSFWorkbook wb = new HSSFWorkbook(); HSSFFont font = wb.createFont(); font.setColor(Font.COLOR_RED); font.setBoldweight(Font.BOLDWEIGHT_BOLD); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setFont(font);/* w w w.ja v a 2 s . co m*/ Sheet sheet = wb.createSheet(); Row row = sheet.createRow(0); Cell cell = createExcelCell(sheet, row, 0, 256 * 100); cell.setCellStyle(cellStyle); cell.setCellValue("An error occurred while uploading!!!"); return createOutputStream(wb); }
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 ww. ja v a 2 s .c om //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;//from w w w .jav a 2 s. c o 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
/** * Returns the head style//from w ww. j av a2s. co m * * @param _workbook * excell work book * @return the head style */ protected HSSFCellStyle getHeaderStyle(HSSFWorkbook _workbook) { HSSFCellStyle headerStyle = _workbook.createCellStyle(); headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); HSSFFont headFont = _workbook.createFont(); headFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); headerStyle.setFont(headFont); return headerStyle; }
From source file:com.pureinfo.srm.project.model.compile.helper.CompileExcelExportHelper.java
License:Open Source License
/** * Returns the date style in excel.//from w w w . ja v a 2 s .c om * * @param _workbook * excell work book * @return the date style in excel. */ protected HSSFCellStyle getDateStyle(HSSFWorkbook _workbook) { HSSFCellStyle dateStyle = _workbook.createCellStyle(); HSSFDataFormat fmt = _workbook.createDataFormat(); dateStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("yy-mm")); HSSFFont font = _workbook.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); dateStyle.setWrapText(true); dateStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); dateStyle.setFont(font); return dateStyle; }
From source file:com.pureinfo.srm.project.model.compile.helper.CompileExcelExportHelper.java
License:Open Source License
protected HSSFCellStyle getDoubleStyle(HSSFWorkbook _workbook) { HSSFCellStyle doubleStyle = _workbook.createCellStyle(); HSSFFont font = _workbook.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); doubleStyle.setWrapText(true);/* ww w . ja v a2s. c o m*/ HSSFDataFormat fmt = _workbook.createDataFormat(); doubleStyle.setDataFormat(fmt.getFormat("0.00")); doubleStyle.setFont(font); return doubleStyle; }
From source file:com.pureinfo.srm.project.model.compile.helper.CompileExcelExportHelper.java
License:Open Source License
/** * Returns the head style/* w ww . ja va 2 s . c o m*/ * * @param _workbook * excell work book * @return the head style */ protected HSSFCellStyle getHeaderStyle(HSSFWorkbook _workbook) { HSSFCellStyle headerStyle = _workbook.createCellStyle(); headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); HSSFFont headFont = _workbook.createFont(); headFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); headerStyle.setFont(headFont); headerStyle.setWrapText(true); return headerStyle; }
From source file:com.qcadoo.mes.assignmentToShift.print.xls.AssignmentToShiftXlsStyleHelper.java
License:Open Source License
private HSSFCellStyle getHeaderStyle(final HSSFWorkbook workbook, final short borderLeft, final short borderRight, final short alignment, final short boldweight) { HSSFCellStyle style = workbook.createCellStyle(); style.setBorderTop(HSSFCellStyle.BORDER_MEDIUM); style.setBorderLeft(borderLeft);/* ww w . j a v a 2 s. co m*/ style.setBorderRight(borderRight); style.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM); style.setAlignment(alignment); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); style.setIndention((short) 3); style.setWrapText(true); style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); Font font = workbook.createFont(); font.setFontName(HSSFFont.FONT_ARIAL); font.setFontHeightInPoints((short) 12); font.setBoldweight(boldweight); style.setFont(font); return style; }