aspose file tools*
The moose likes Other Open Source Projects and the fly likes Excel reporting through Jasperreports Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Excel reporting through Jasperreports " Watch "Excel reporting through Jasperreports " New topic
Author

Excel reporting through Jasperreports

manish kkum
Greenhorn

Joined: Feb 03, 2004
Posts: 5
Hi,
I am trying to generate excel reports through Jasperreports in a web application (still in evaluation mode). I have written the following JSP which is supposed to generate the Excel report. But When I run the example, all the garbage (I think, binary form of the report) comes up in the browser. I have set the content type as response.setContentType("appcation/excel"). Then why is it showing in binary form ?
Has anybody use the JAsperreports for excel reporting ina web application before ?
thanks in advance...
regards,
manish
<%System.setProperty("jasper.reports.compile.class.path",
application.getRealPath("/WEB-INF/lib/jasperreports-0.5.1.jar") +
System.getProperty("path.separator") +
application.getRealPath("/WEB-INF/classes/")
);

System.setProperty(
"jasper.reports.compile.temp",
application.getRealPath("/reports/")
);

//ServletOutputStream output = response.getOutputStream();

ByteArrayOutputStream baos = new ByteArrayOutputStream();

JasperDesign jasperDesign = JasperManager.loadXmlDesign("C:/jakarta-tomcat-5.0.16/webapps/jasper-webapp/reports/testReport.xml");

JasperReport jasperReport = JasperManager.compileReport(jasperDesign);

Map parameters = new HashMap();

Connection conn = getConnection();

JasperPrint jasperPrint = JasperManager.fillReport(jasperReport,parameters, conn);

File destFile = new File("C:/jakarta-tomcat-5.0.16/webapps/jasper-webapp/reports/", jasperPrint.getName() + ".xls");



JRXlsExporter exporter = new JRXlsExporter();


//JRHtmlExporter exporter = new JRHtmlExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString());
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
exporter.exportReport();
byte[] bytes = null;

bytes = baos.toByteArray();
System.out.println("testing: " + bytes.length);

response.setContentType("application/excel");

//response.setHeader("Content-disposition","inline; filename=foobar.xls" );

response.setContentLength(bytes.length);
try{
baos.close();
ServletOutputStream ouputStream = response.getOutputStream();
//response.setContentType("application/vnd.ms-excel");
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
}
catch(Exception e)
{e.printStackTrace();}

%>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Excel reporting through Jasperreports
 
Similar Threads
Same Jasper Report keeps opening
JasperReports + JSP
Jasper Report - Text Exporter
How to display jasper report in jsp
Jasper Reports Excel Output