Pues ya quedó con POI de Apache y la solución esta aquí:
HSSFWorkbook objWB = new HSSFWorkbook();
HSSFSheet hoja1 = objWB.createSheet("productos");
HSSFRow fila = hoja1.createRow((short) 0);
fila.createCell((short) 0).setCellValue(new HSSFRichTextString("ID"));
fila.createCell((short) 1).setCellValue(new HSSFRichTextString("UBICACION"));
fila.createCell((short) 2).setCellValue(new HSSFRichTextString("SKU"));
fila.createCell((short) 3).setCellValue(new HSSFRichTextString("NOMBRE"));
fila.createCell((short) 4).setCellValue(new HSSFRichTextString("DESCRIPCION"));
fila.createCell((short) 5).setCellValue(new HSSFRichTextString("MARCA"));
fila.createCell((short) 6).setCellValue(new HSSFRichTextString("MODELO"));
fila.createCell((short) 7).setCellValue(new HSSFRichTextString("FRACCION"));
fila.createCell((short) 8).setCellValue(new HSSFRichTextString("EXISTENCIA"));
fila.createCell((short) 9).setCellValue(new HSSFRichTextString("UNIDADES"));
fila.createCell((short) 10).setCellValue(new HSSFRichTextString("PRECIO"));
fila.createCell((short) 11).setCellValue(new HSSFRichTextString("IVA"));
List productos = productoManager.getPorConfiguracion();
int row = 1;
for (Producto producto : productos) {
fila = hoja1.createRow(row++);
fila.createCell((short) 0).setCellValue(producto.getId());
fila.createCell((short) 1).setCellValue(producto.getUbicacion() != null ? new HSSFRichTextString(producto.getUbicacion()) : new HSSFRichTextString(""));
fila.createCell((short) 2).setCellValue(new HSSFRichTextString(producto.getSku()));
fila.createCell((short) 3).setCellValue(new HSSFRichTextString(producto.getNombre()));
fila.createCell((short) 4).setCellValue(new HSSFRichTextString(producto.getDescripcion()));
fila.createCell((short) 5).setCellValue(producto.getMarca() != null ? new HSSFRichTextString(producto.getMarca()) : new HSSFRichTextString());
fila.createCell((short) 6).setCellValue(producto.getModelo() != null ? new HSSFRichTextString(producto.getModelo()) : new HSSFRichTextString());
fila.createCell((short) 7).setCellValue(producto.getFraccion());
fila.createCell((short) 8).setCellValue(producto.getExistencia());
fila.createCell((short) 9).setCellValue(producto.getUnidadMedida() != null ? new HSSFRichTextString(producto.getUnidadMedida()) : new HSSFRichTextString());
fila.createCell((short) 10).setCellValue(new HSSFRichTextString(producto.getPrecioUnitario().toPlainString()));
fila.createCell((short) 11).setCellValue(new HSSFRichTextString(producto.getIva().toPlainString()));
}
getResponse().setContentType("application/vnd.ms-excel");
// getResponse().setContentLength(byteArrayOutputStream.toByteArray().length);
getResponse().setHeader("Content-disposition",
"attachment; filename=\"productos.xls\"");
ServletOutputStream out;
try {
out = getResponse().getOutputStream();
objWB.write(out);
} catch (IOException e) {
e.printStackTrace();
}
Realmente rápido y sin tanta complicación...
HSSFWorkbook objWB = new HSSFWorkbook();
HSSFSheet hoja1 = objWB.createSheet("productos");
HSSFRow fila = hoja1.createRow((short) 0);
fila.createCell((short) 0).setCellValue(new HSSFRichTextString("ID"));
fila.createCell((short) 1).setCellValue(new HSSFRichTextString("UBICACION"));
fila.createCell((short) 2).setCellValue(new HSSFRichTextString("SKU"));
fila.createCell((short) 3).setCellValue(new HSSFRichTextString("NOMBRE"));
fila.createCell((short) 4).setCellValue(new HSSFRichTextString("DESCRIPCION"));
fila.createCell((short) 5).setCellValue(new HSSFRichTextString("MARCA"));
fila.createCell((short) 6).setCellValue(new HSSFRichTextString("MODELO"));
fila.createCell((short) 7).setCellValue(new HSSFRichTextString("FRACCION"));
fila.createCell((short) 8).setCellValue(new HSSFRichTextString("EXISTENCIA"));
fila.createCell((short) 9).setCellValue(new HSSFRichTextString("UNIDADES"));
fila.createCell((short) 10).setCellValue(new HSSFRichTextString("PRECIO"));
fila.createCell((short) 11).setCellValue(new HSSFRichTextString("IVA"));
List
int row = 1;
for (Producto producto : productos) {
fila = hoja1.createRow(row++);
fila.createCell((short) 0).setCellValue(producto.getId());
fila.createCell((short) 1).setCellValue(producto.getUbicacion() != null ? new HSSFRichTextString(producto.getUbicacion()) : new HSSFRichTextString(""));
fila.createCell((short) 2).setCellValue(new HSSFRichTextString(producto.getSku()));
fila.createCell((short) 3).setCellValue(new HSSFRichTextString(producto.getNombre()));
fila.createCell((short) 4).setCellValue(new HSSFRichTextString(producto.getDescripcion()));
fila.createCell((short) 5).setCellValue(producto.getMarca() != null ? new HSSFRichTextString(producto.getMarca()) : new HSSFRichTextString());
fila.createCell((short) 6).setCellValue(producto.getModelo() != null ? new HSSFRichTextString(producto.getModelo()) : new HSSFRichTextString());
fila.createCell((short) 7).setCellValue(producto.getFraccion());
fila.createCell((short) 8).setCellValue(producto.getExistencia());
fila.createCell((short) 9).setCellValue(producto.getUnidadMedida() != null ? new HSSFRichTextString(producto.getUnidadMedida()) : new HSSFRichTextString());
fila.createCell((short) 10).setCellValue(new HSSFRichTextString(producto.getPrecioUnitario().toPlainString()));
fila.createCell((short) 11).setCellValue(new HSSFRichTextString(producto.getIva().toPlainString()));
}
getResponse().setContentType("application/vnd.ms-excel");
// getResponse().setContentLength(byteArrayOutputStream.toByteArray().length);
getResponse().setHeader("Content-disposition",
"attachment; filename=\"productos.xls\"");
ServletOutputStream out;
try {
out = getResponse().getOutputStream();
objWB.write(out);
} catch (IOException e) {
e.printStackTrace();
}
Realmente rápido y sin tanta complicación...
Comentarios