Java - jasperReport y excel

 
Vista:

jasperReport y excel

Publicado por Oscar (1 intervención) el 27/11/2006 13:23:59
Hola a todos,

tengo un problema a la hora de presentar un report en excel.
Lo que quiero hacer es presentar el report en excel (llamado desde un servlet) sin la necesidad de tener que crear un fichero destino para guardar el excel. Este es el codigo:

Muchas gracias.


parameters.put("imprimir", new Boolean(false));

response.setContentType("application/vnd.ms-excel");

JasperCompileManager.compileReportToFile
(context.getRealPath(request.getParameter("report")+".jrxml"));

reportFile = new File(context.getRealPath(request.getParameter("report")+".jasper"));
if(!reportFile.exists())throw new JRRuntimeException
("File WebappReport.jasper not found. The report design must be compiled first.");


JasperPrint jasperPrint = null;
JasperReport jasperReport = (JasperReport)JRLoader.loadObject(reportFile.getPath());
jasperPrint=JasperFillManager.fillReport(jasperReport, parameters,connection);

JRXlsExporter exporterXLS = new JRXlsExporter();

exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT, jasperPrint);
exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_WRITER, out);
exporterXLS.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET,Boolean.FALSE);

exporterXLS.setParameter
(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);

exporterXLS.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);

exporterXLS.exportReport();
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder