public void postProcessXLS() {
if (movimientos == null) {
cargaTablaDinamica();
}
System.
out.
println("Entre al metodo postProcess");
// HSSFWorkbook wb = (HSSFWorkbook) document;
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Movimientos");
// wb.setSheetName(0, "Ejemplo"); //Asignamos nombre a la hoja de calculo
// HSSFRow header = sheet.createRow(0);
HSSFRow fila = null;
//HSSFRow fila = sheet.getRow(1);
/* Llenar las cosas*/
for (int i = 0; i < movimientos.size(); i++) {
fila = sheet.createRow(i);
for (int j = 0; j < 5; j++) {
fila.createCell(j);
}
/* fila.getCell(0).setCellValue("Fecha");
fila.getCell(1).setCellValue("Descripcion");
fila.getCell(2).setCellValue("Serie");
fila.getCell(3).setCellValue("Monto");
fila.getCell(4).setCellValue("Saldo");*/
fila.getCell(0).setCellValue(movimientos.get(i).getFecha().toLocaleString());
fila.getCell(1).setCellValue(movimientos.get(i).getDescripcion());
fila.getCell(2).setCellValue(movimientos.get(i).getSerie());
fila.getCell(3).setCellValue((double)movimientos.get(i).getMonto());
fila.getCell(4).setCellValue((double)movimientos.get(i).getSaldo());
}
/*
HSSFCellStyle cellStyle = wb.createCellStyle(); //estilo para la primera fila
HSSFCellStyle estilo = wb.createCellStyle(); // otro estilo para la segunda fila
HSSFCellStyle estilo2 = wb.createCellStyle();
cellStyle.setFillForegroundColor(HSSFColor.LIGHT_ORANGE.index);// color Naranjo
cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
estilo.setFillForegroundColor(HSSFColor.LIGHT_BLUE.index);//estilo para la segunda fila
estilo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
estilo2.setFillForegroundColor(HSSFColor.LIGHT_GREEN.index);
estilo2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);*/
System.
out.
println("El documento pesa : " + wb.
getBytes().
length);
try {
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
// response.resetBuffer();
response.setContentLength(wb.getBytes().length);
response.setContentType("application/vnd.ms-excel");
// System.out.println("RespuestA ? : " + response.getOutputStream().toString());
// ServletOutputStream out = response.getOutputStream();
ServletOutputStream out = response.getOutputStream();
out.write(wb.getBytes());
// out.flush();
out.close();
// baosPDF.flush();
// baosPDF.close();
facesContext.responseComplete();
System.
out.
println("Error : " + e.
getMessage()); e.printStackTrace();
}
// estilo2.setFont(HSSFFont.);
// Este ciclo pintara todas las celdas de la fila 1
/* for (int i = 0; i < header.getPhysicalNumberOfCells(); i++) {
//header.getPhysicalNumberOfCells obtiene el numero de celdas de la fila
HSSFCell cell = header.getCell(i);
cell.setCellStyle(cellStyle);//le asigna el estilo a cada celda de la primera fila
sheet.autoSizeColumn((short) i); // Deja las columnas en un tamaño que se vea todo bien.
System.out.println("Numero : " + i);//Cantidad de celdas rellenadas
}
// pruebas con las columnas
// Pintara toda la columna 3 de todas las filas.
for (int i = 0; i < sheet.getPhysicalNumberOfRows(); i++) {
HSSFRow fila = sheet.getRow(i);
HSSFCell cell = fila.getCell(2);
cell.setCellStyle(estilo2);
}
/*Este ciclo pintara todas las celdas de la fila 2
for (int i = 0; i < fila.getPhysicalNumberOfCells(); i++) {
HSSFCell cell = fila.getCell(i);
cell.setCellStyle(estilo);
}*/
}