起步软件技术论坛
搜索
 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2472|回复: 1

[分享] Wex5 poi 形式导出excel

[复制链接]

3

主题

7

帖子

33

积分

新手上路

Rank: 1

积分
33
QQ
发表于 2017-3-21 15:43:01 | 显示全部楼层 |阅读模式
按钮事件:
        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;
        }

39

主题

168

帖子

421

积分

中级会员

Rank: 3Rank: 3

积分
421
QQ
发表于 2017-3-29 21:04:21 | 显示全部楼层
//取值逻辑并写入excel中,具体网上查询poi生成excel
            createExcel(sheet, cellstyle);
            
能写个简单的例子吗?
            
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|X3技术论坛|Justep Inc.    

GMT+8, 2024-5-9 08:11 , Processed in 0.054699 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表