|
按钮事件:
Model.prototype.onClickExportExcel = function(event){
var row = this.comp("assertCheckScheduleData").getFirstRow();
var rp_id = row.val("rp_id");
//导出 excel
window.location.href="/baas/lam/processrequest/exportExcel?rp_id="+rp_id;
};
其中/processrequest/exportExcel 是指对应baas后台中service文件中对应的action方法
后台action
public static JSONObject exportExcel(JSONObject params, ActionContext context) throws JsonGenerationException, JsonMappingException, IOException, WxErrorException, SQLException,
NamingException {
//获取request对象
HttpServletRequest request = (HttpServletRequest)context.get(ActionContext.REQUEST);
//获取response对象
HttpServletResponse response = (HttpServletResponse)context.get(ActionContext.RESPONSE);
//如参,请求id
String rp_id = request.getParameter("rp_id");
System.out.println(rp_id);
JSONObject ret =new JSONObject();
OutputStream ouputStream=null;
try{
XSSFWorkbook workbook =new XSSFWorkbook();
XSSFSheet sheet =workbook.createSheet();
//设置字体样式
XSSFFont font =workbook.createFont();
font.setFontName("Verdana");
font.setBoldweight((short) 100);
font.setFontHeight((short) 300);
XSSFCellStyle cellstyle=workbook.createCellStyle();
cellstyle.setFont(font);
//取值逻辑并写入excel中,具体网上查询poi生成excel
createExcel(sheet, cellstyle);
ouputStream = response.getOutputStream();
response.reset();
response.setHeader("Cache-Control", "pre-check=0, post-check=0, max-age=0");
response.addHeader("Content-Disposition", "attachment; filename=bbb.xlsx");
workbook.write(ouputStream);
ouputStream.flush();
}catch(Exception e){
e.printStackTrace();
}finally{
ouputStream.close();
}
return null;
}
|
|