Jump to content
Changes to the Jaspersoft community edition download ×

Unable to export jasper report in excel format


mfarooq

Recommended Posts

Hi,

 

I am using using jasper reports to generate my application reports but when I try to export my report in excel format but when excel file downloaded it contain rough data.

 

Below is my java source to export jasper report in excel format. Please help.

 

 

byte[] pdf_ = null;

Connection connection_ = DatabaseHandler.getConnection();

 

String jrxml_ = "/reports/jrxml/detailedxls.jrxml";

 

jrxml_ = this.getClass().getResource(jrxml_).getFile();

 

JasperDesign jasperDesign_ = JRXmlLoader.load(jrxml_);

 

JasperReport jasperReport_ = JasperCompileManager.compileReport(jasperDesign_);

 

ByteArrayOutputStream outputStream_ = new ByteArrayOutputStream();

 

if (null != paramMap)

{

JasperFillManager.fillReportToStream(jasperReport_, outputStream_,paramMap, connection_);

 

}

 

else

{

 

JasperFillManager.fillReportToStream(jasperReport_, outputStream_,new HashMap(), connection_);

 

}

 

JasperPrint jasperPrint_ = null;

 

jasperPrint_ = JasperFillManager.fillReport(jasperReport_,paramMap, connection_);

 

JRXlsExporter exporterXLS = new JRXlsExporter();

 

exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT,jasperPrint_);

 

exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_STREAM,outputStream_);

 

exporterXLS.exportReport();

 

pdf_ = outputStream_.toByteArray();

 

 

 

httpServletResponse.setContentType ("application/vnd.ms-excel");

 

httpServletResponse.addHeader("Content-disposition","attachment; filename=" + reportName_.toString() + ".xls");

 

httpServletResponse.getOutputStream().write(pdf_);

 

 

Thanks in advance.

[file name=R_Detail_2008_01_14_170845-c4ef16d809a8bb6015619f98b74b8eb5.xls size=58034]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/R_Detail_2008_01_14_170845-c4ef16d809a8bb6015619f98b74b8eb5.xls[/file] [file name=R_Detail_2008_01_14_170845-c4ef16d809a8bb6015619f98b74b8eb5.xls size=58034]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/R_Detail_2008_01_14_170845-c4ef16d809a8bb6015619f98b74b8eb5.xls[/file]

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