Jump to content
Changes to the Jaspersoft community edition download ×

Zero file size of exported XLS file


tbiswas

Recommended Posts

Hello,

I am new to JasperServer and iReport tools. I have created one .jasper file using iReport for testing. In my tomcat I have used all the required JAR files for JasperServer. I have created one JSP file and want to create report based on that .jasper file into different file format like PDF, CSV, RTF, XLS etc. My JSP code is there with this topic in the Code section.

Problem with this code is, all the other file format is working properly except the xls format. It produsing an empty file with no data.

Can anybody please help me on this issue?

Thanks in advance...

Tanmoy

Code:
 <%@ page language="java" import="net.sf.jasperreports.engine.*,net.sf.jasperreports.engine.export.*" %><%@ page import="java.sql.*,java.io.*" %><%            String filename = "D:/Program Files/jasperserver-ce-3.7.0/ireport/ireport/reports/test.jasper";            String reporttype = "xls";            Class.forName("com.mysql.jdbc.Driver");            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/myDB", "root", "root");            System.out.println("Connection Established");            JasperPrint jasperPrint = JasperFillManager.fillReport(filename, null, conn);            System.out.println("Report Created...");            OutputStream ouputStream = response.getOutputStream();            JRExporter exporter = null;            if ("pdf".equalsIgnoreCase(reporttype)) {                response.setContentType("application/pdf");                exporter = new JRPdfExporter();                exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);                exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);            } else if ("rtf".equalsIgnoreCase(reporttype)) {                response.setContentType("application/rtf");                response.setHeader("Content-Disposition", "inline; filename=\"file.rtf\"");                exporter = new JRRtfExporter();                exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);                exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);            } else if ("html".equalsIgnoreCase(reporttype)) {                exporter = new JRHtmlExporter();                exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);                exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);            } else if ("xls".equalsIgnoreCase(reporttype)) {                response.setContentType("application/xls");                response.setHeader("Content-Disposition", "inline; filename=\"file.xls\"");                exporter = new JRXlsExporter();                exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);                exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);            } else if ("csv".equalsIgnoreCase(reporttype)) {                response.setContentType("application/csv");                response.setHeader("Content-Disposition", "inline; filename=\"file.csv\"");                exporter = new JRCsvExporter();                exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);                exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);            }            try {                exporter.exportReport();            } catch (Exception e) {                System.out.println(e);            } finally {                if (ouputStream != null) {                    try {                        ouputStream.close();                    } catch (IOException ex) {                    }                }            }%>
Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...