2 Replies Latest reply: Aug 9, 2010 4:45 AM by 807567 RSS

    Zero file size of exported XLS file

    807567
      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 below: -
      <%@ 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) {
                          }
                      }
                  }
      %>
      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?
      Am I doing any silly mistake?

      I have posted this in jasper server's forum, but they didn't say anything........

      I need help on this.

      Thanks in advance...

      Tanmoy