Jump to content

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.xls size=64472]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/R_Detail_2008_01_14_170845.xls[/file] [file name=R_Detail_2008_01_14_170845.xls size=64472]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/R_Detail_2008_01_14_170845.xls[/file]

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

StringBuffer sbFile = new StringBuffer("C:").append(File.separator).append(jenisLaporan).append(".xls");

JExcelApiExporter exporterAPIXLS = new JExcelApiExporter();

exporterAPIXLS.setParameter(JExcelApiExporterParameter.JASPER_PRINT, jasperPrint);

exporterAPIXLS.setParameter(JExcelApiExporterParameter.OUTPUT_FILE_NAME, sbFile.toString());

exporterAPIXLS.setParameter(JExcelApiExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);

exporterAPIXLS.setParameter(JExcelApiExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);

exporterAPIXLS.setParameter(JExcelApiExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);

exporterAPIXLS.exportReport();

 

you can use my code to compile xls

 

Regards,

Link to comment
Share on other sites

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