How to generate XLS(Excel) file in java using jrxml?

 

The following is the code for report generation of Excel(XLS) report using JAVA JRXML.Its generating a blank file.I am calling the method by this:
 
String hello=xls(JRXML_FILE, PDF_FILE, JASPER_FILE);
Where JRXML_FILE is the poath of JRXML file
Where PDF_FILE is the destination path of the Excel  file
JASPER_FILE is the link to the JASPER file.
PLS HELP!
 
 
[code]
public String xls(String filename, String dest_filename, String jasper_file){ 
try{ 
//File sourceFile = new File(filename); 
//HashMap hm = new HashMap();
 
 
       // JasperPrint print = JasperFillManager.fillReport(filename, hm, new JREmptyDataSource());  
1
JasperCompileManager.compileReportToFile(filename, jasper_file);
File sourceFile = new File(jasper_file);  
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(sourceFile);  
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap<String, Object>());  
 
File destFile = new File(dest_filename); 
 
JRXlsExporter exporter = new JRXlsExporter(); 
 
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE);
exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString()); 
exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE); 
exporter.exportReport(); 
 
catch(Throwable t){return "error: " + t.getMessage();} 
return "XLS Report generated Successfully!"; 
[/code]
abbhiseth's picture
Joined: Oct 20 2013 - 11:07pm
Last seen: 9 years 4 months ago

0 Answers:

No answers yet
Feedback
randomness