Expand my Community achievements bar.

Excel reporting

Avatar

Level 7

I want to trigger my sling servlet on button click and that servlet get trigerred after that and excel file must be downloaded automatically in browser .

I have done the coding its working withot any issue ....but the automatically download iafter clicking on buttton on bbrwser itself in dwoload folder that is what I am not able to acheive

when I work with simple fileoutput stream it works excel file get downloaded and i can open it and see it .(working code )

File excelfile = new File("customisedReport.xlsx");
FileOutputStream fileOutputStream = new FileOutputStream(excelfile);
workbook.write(fileOutputStream);
fileOutputStream.close();

but if i change the above code below like this : it won't work (nothing happens on clicking on button )

String reportName="customisedCommentReport.xlsx";
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition", "attachment; filename="+reportName);
ServletOutputStream outputStream = response.getOutputStream();
workbook.write(outputStream);
outputStream.flush();
outputStream.close();
workbook.close();

please suggest what can be the issue

Please note : google chrome i m using , apache poi , XSSFworkbook i used ,

1 Reply

Avatar

Level 7

inside my js

funReport= function(t, e) {

                var presenturl=window.location.href;

                $.ajax({

                    type: "GET",

                    url: "/bin/excelreporting",

                    data: {

                        'presenturl':presenturl,

                    }

                })

               

            }

Directing hitting the URL /bin/excelreporting it works but on click of button this is not working ?