Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

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 ?

The ultimate experience is back.

Join us in Vegas to build skills, learn from the world's top brands, and be inspired.

Register Now