Jump to content
We've recently updated our Privacy Statement, available here ×

pbm in xls format export


kumarasamymk

Recommended Posts

Dear All,

I have a small problem in xls format report generation.

When i'm exporting the report into File System it's working fine, But when i'm displaying directly in the browser it's not working.

 

My Code is

 

File reportFile = new File(session.getAttribute("reportPath"«»)+repfname+".jasper"«»);

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

Map parameters = (Map)session.getAttribute("param"«»);

 

JasperPrint jasperPrint = (JasperPrint) JasperFillManager.fillReport(jasperReport,parameters, new reportData(Sql,QryType));

JRXlsExporter jasperXlsExportMgr = new JRXlsExporter();

 

byte[] bytes = null;

 

ByteArrayOutputStream xlsReport = new ByteArrayOutputStream();

 

jasperXlsExportMgr.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

jasperXlsExportMgr.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);

jasperXlsExportMgr.setParameter(JRXlsExporterParameter.IS_AUTO_DETECT_CELL_TYPE, java.lang.Boolean.FALSE);

jasperXlsExportMgr.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, java.lang.Boolean.TRUE);

jasperXlsExportMgr.setParameter(JRExporterParameter.OUTPUT_STREAM, xlsReport);

jasperXlsExportMgr.exportReport();

bytes = xlsReport.toByteArray();

response.setHeader("Content-Disposition", "attachment; filename=printExcel.XLS"«»);

response.setContentType("application/x-msexcel"«»);

response.setHeader("Pragma", "public"«»);

response.setHeader("Cache-Control", "max-age=0"«»);

ServletOutputStream ouputStream = response.getOutputStream();

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

ouputStream.flush();

ouputStream.close();

 

Post edited by: kumarasamymk, at: 2006/12/28 13:33

Post edited by: kumarasamymk, at: 2006/12/28 13:34

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

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