Jump to content
Changes to the Jaspersoft community edition download ×

Can't view the xls exported file

Recommended Posts

By: andre_a_s - andre_a_s

Can't view the xls exported file

2006-05-22 12:54

Hi all :)

I'm having problems when exporting to XLS.

When I export to PDF, everything is fine, but when I try to export XLS, it exports and I cannot open it, "unable to open file".


That's my code to generate the PDF:


String fileName = new SimpleDateFormat("ddMMyyyy-HHmmss").format(new Date()) + ".pdf";

exporter = new JRPdfExporter();

response.setHeader("Content-Disposition","attachment;filename="" + fileName + """);


exporter.setParameter(JRPdfExporterParameter.JASPER_PRINT, print);

exporter.setParameter(JRPdfExporterParameter.OUTPUT_STREAM, new BufferedOutputStream(response.getOutputStream()));



I just copied the code and changed a little for the XLS:



String fileName = new SimpleDateFormat("ddMMyyyy-HHmmss").format(new Date()) + ".xls";

exporter = new JRXlsExporter();

response.setHeader("Content-Disposition","attachment;filename="" + fileName + """);


exporter.setParameter(JRXlsExporterParameter.JASPER_PRINT, print);

exporter.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, new BufferedOutputStream(response.getOutputStream()));

exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE);



I can't generate a phisical file like "c:\file.xls", I need to do it like the PDF, the user need to download the file.

Someone help me? =]





By: Anurag - anurag1005

RE: Can't view the xls exported file

2006-05-23 00:04

Please try with this code


This code will send the Response back to screen fromn where you ahev tried to generate the report

and user can save the generated file to view.





ServletContext context = this.getServletConfig().getServletContext();

File reportFile = new File(context.getRealPath("/reports/WebappReport.jasper"));

JasperReport jasperReport = (JasperReport)JRLoader.loadObject(reportFile.getPath());

Map parameters = new HashMap();

parameters.put("ReportTitle", "Address Report");

parameters.put("BaseDir", reportFile.getParentFile());

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, new WebappDataSource());

JRXlsExporter exporter = new JRXlsExporter();


ByteArrayOutputStream xlsReport = new ByteArrayOutputStream();

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, xlsReport);



System.out.println("Sixe of byte array:"+xlsReport.size());

bytes = xlsReport.toByteArray();





ServletOutputStream ouputStream = response.getOutputStream();

ouputStream.write(bytes, 0, bytes.length);









By: andre_a_s - andre_a_s

RE: Can't view the xls exported file

2006-05-23 09:10

Really thanx Anurag !!!

It workd fine. But tell me... why the way've I tried did not work?

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

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...