rushi2440
20 Jan 2012, 2:16 AM
Hello sencha forum member i need some support from you to generate the excel report and then download it with one click.
I am working on extjs 4.0.2a along with Java. In java framework such as Hibernate/JPA and Spring. I am using Jasper Report to generate the report in excel and pdf. I am able to generate the report using it. But the problem is that I am not able to download it in my browser. Also my browser didn't prompt me to save or cancel the report generated.
I am making request to server to generate the excel report using
Ext.Ajax.request({
url: 'task/GetTaskReportXLS.action',
success : function(response, option){
console.log("success");
}
,failure :function(response, option){
console.log("failure");
}
,scope : this
});
on my server side I am generating the excel report with below code
Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/contact","**","**");
Map params = getParameters(openSession);
Date date = new Date();
OutputStream outputfile = new FileOutputStream(new File("C:\\report\\xls\\JasperReport"+date.getDate()+"-"+date.getMonth()+"-"+date.getYear()+"-"+date.getTime()+".xls"));
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition","inline; filename=\"gantt.xls\"");
response.addHeader("Content-Disposition", "attachment");
JasperDesign jasperDesign = JRXmlLoader.load(this.getClass().getResourceAsStream("/com/gantt/report/ganttreport.jrxml"));
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperprint = JasperFillManager.fillReport(jasperReport, params,con);
JRExporter exporterXLS = new JRXlsExporter();
exporterXLS.setParameter(JRExporterParameter.JASPER_PRINT, jasperprint);
exporterXLS.setParameter(JRExporterParameter.OUTPUT_STREAM, outputfile);
exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_COLLAPSE_ROW_SPAN, Boolean.TRUE);
exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS, Boolean.TRUE);
exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_DETECT_CELL_TYPE, Boolean.FALSE);
exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_IGNORE_GRAPHICS, Boolean.TRUE);
exporterXLS.exportReport();
when i click the export button the process executes and as the response on my firebug console i am getting headers as
Response Headers
Content-Disposition attachment
Content-Length 0
Content-Type application/vnd.ms-excel
Date Fri, 20 Jan 2012 10:00:49 GMT
Server Apache-Coyote/1.1
but still my download prompt not appear to save my excel report. Help me to point out what things I am doing wrong here.
I am using extjs 4.0.2a mvc architecture with Java.
Yogendra Singh
Sr. Programmer
Kintudesigns.com
I am working on extjs 4.0.2a along with Java. In java framework such as Hibernate/JPA and Spring. I am using Jasper Report to generate the report in excel and pdf. I am able to generate the report using it. But the problem is that I am not able to download it in my browser. Also my browser didn't prompt me to save or cancel the report generated.
I am making request to server to generate the excel report using
Ext.Ajax.request({
url: 'task/GetTaskReportXLS.action',
success : function(response, option){
console.log("success");
}
,failure :function(response, option){
console.log("failure");
}
,scope : this
});
on my server side I am generating the excel report with below code
Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/contact","**","**");
Map params = getParameters(openSession);
Date date = new Date();
OutputStream outputfile = new FileOutputStream(new File("C:\\report\\xls\\JasperReport"+date.getDate()+"-"+date.getMonth()+"-"+date.getYear()+"-"+date.getTime()+".xls"));
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition","inline; filename=\"gantt.xls\"");
response.addHeader("Content-Disposition", "attachment");
JasperDesign jasperDesign = JRXmlLoader.load(this.getClass().getResourceAsStream("/com/gantt/report/ganttreport.jrxml"));
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperprint = JasperFillManager.fillReport(jasperReport, params,con);
JRExporter exporterXLS = new JRXlsExporter();
exporterXLS.setParameter(JRExporterParameter.JASPER_PRINT, jasperprint);
exporterXLS.setParameter(JRExporterParameter.OUTPUT_STREAM, outputfile);
exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_COLLAPSE_ROW_SPAN, Boolean.TRUE);
exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS, Boolean.TRUE);
exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_DETECT_CELL_TYPE, Boolean.FALSE);
exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
exporterXLS.setParameter(JRXlsAbstractExporterParameter.IS_IGNORE_GRAPHICS, Boolean.TRUE);
exporterXLS.exportReport();
when i click the export button the process executes and as the response on my firebug console i am getting headers as
Response Headers
Content-Disposition attachment
Content-Length 0
Content-Type application/vnd.ms-excel
Date Fri, 20 Jan 2012 10:00:49 GMT
Server Apache-Coyote/1.1
but still my download prompt not appear to save my excel report. Help me to point out what things I am doing wrong here.
I am using extjs 4.0.2a mvc architecture with Java.
Yogendra Singh
Sr. Programmer
Kintudesigns.com