开发者

How to let user download the data in database to an excel sheet file from web application in Java/Struts?

开发者 https://www.devze.com 2023-02-14 07:49 出处:网络
I want to generate a report which includes an excel sheet which is generated from the data from the database . I am using Apache POI HSSF for creating the excel sheet file in the model.

I want to generate a report which includes an excel sheet which is generated from the data from the database . I am using Apache POI HSSF for creating the excel sheet file in the model.

Now how t开发者_JS百科o let the user download the file i have created ?


Just use a servlet. Feed response.getOutputStream() to POI HSSF to write the workbook to. Most important bit is the Content-Disposition response header. If you set it to attachment, then the browser will pop a Save As dialogue.

response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=name.xls");
WritableWorkbook workBook = Workbook.createWorkbook(response.getOutputStream());
// ...

Then let the download URL point to that servlet, if necessary with some request parameters or path info.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号