jsp导出excel

    /***
     * 导出excel表格
     * 提交方式只能是同步!!
     * @param select
     * @param model
     * @param session
     * @return
     * @throws IOException
     * @throws WriteException
     * @throws ParseException
     * @throws Exception
     */
    @RequestMapping(value = "/insertTable.do")
    public String insertTable( Model model,HttpServletResponse response,SelectCondition select) throws IOException, WriteException, ParseException {
        //获取文件名字
        String excelName = "兑换明细"+System.currentTimeMillis()+".xls";
        //定义一个输出liu
        OutputStream os = null;
        //清除空白行
        response.reset();
        //设置响应头
        response.setHeader("Content-disposition", "attachment; filename="
                + new String((excelName).getBytes("gbk"), "iso8859-1"));// 设置编码
        response.setContentType("application/msexcel");// 这是输出为EXCEL格式的
        os = response.getOutputStream();
        // 设置第一行的字体样式
        WritableFont wfh = new WritableFont(WritableFont.ARIAL, 12,
                WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,
                Colour.BLACK);
        WritableCellFormat wcf = new WritableCellFormat(wfh);
        wcf.setBackground(Colour.GOLD);
        // 2.生成工作簿
        WritableWorkbook wb = Workbook.createWorkbook(os);
        // 3根据工作薄创建工作表
        WritableSheet sheet = wb.createSheet("工作表1", 0);
        sheet.setColumnView(0, 10);
        sheet.setColumnView(1, 15);
        sheet.setColumnView(2, 15);
        sheet.setColumnView(3, 15);
        sheet.setColumnView(4, 15);
        sheet.setColumnView(5, 15);
        sheet.setColumnView(6, 15);
        sheet.setColumnView(7, 15);
        
        // 4.生成单元格
        Label label = new Label(0, 0, "玩家ID", wcf);
        // 5.工作表中加入单元格
        sheet.addCell(label);

        label = new Label(1, 0, "用户昵称", wcf);
        sheet.addCell(label);

        label = new Label(2, 0, "身份", wcf);
        sheet.addCell(label);

        label = new Label(3, 0, "时间", wcf);
        sheet.addCell(label);

        label = new Label(4, 0, "兑换类型", wcf);
        sheet.addCell(label);

        label = new Label(5, 0, "积分消耗数量", wcf);
        sheet.addCell(label);

        label = new Label(6, 0, "订单号", wcf);
        sheet.addCell(label);

        label = new Label(7, 0, "状态", wcf);
        sheet.addCell(label);
        
        //进行查询
        List list = queryModuleService.selectConvertService(select);
        if(list != null && list.size()>0){
            for(int i=0;i<list.size();i++){
                Map map = (Map) list.get(i);
                label = new Label(0, i + 1, map.get("USER_ID") + "");
                sheet.addCell(label);

                label = new Label(1, i + 1,map.get("NICKNAME") + "");
                sheet.addCell(label);
                //保存身份
                String status = null;
                if(Integer.parseInt(map.get("SPREAD_ACTIVE_TIME").toString())>0){
                    status="推广员";
                }else if(map.get("IS_PROXY").toString().equals("1")){
                    status = "代理";
                }else{
                    status = "会员";
                }
                label = new Label(2, i + 1, status + "");
                sheet.addCell(label);
                //时间格式
                String a = map.get("CONVERT_TIM").toString();
                if(!a.equals("0")){
                    a = DateFormatUtil.longFormatDateStr((Long.parseLong(a)));
                }
                label = new Label(3, i + 1,a + "");
                sheet.addCell(label);
                String convertType = map.get("CONVERT_TYPE").toString();
                if(convertType.equals("1")){
                    status = "房卡";
                }else if(convertType.equals("2")){
                    status="话费";
                }else if(convertType.equals("3")){
                    status="流量";
                }else if(convertType.equals("4")){
                    status="提现";
                }
                label = new Label(4, i + 1,status + "");
                sheet.addCell(label);
                //消耗积分
                String score = map.get("SCORE_NUM").toString();
                label = new Label(5, i + 1,score + " ");
                sheet.addCell(label);
                //订单号
                String order_id = map.get("ORDER_ID").toString();
                label = new Label(6, i + 1,order_id + "");
                sheet.addCell(label);
                
                //状态
                String state = map.get("ORDER_ID").toString();
                if(state.equals("1")){
                    status="已完成";
                }else if(state.equals("2")){
                    status="处理中";
                }else if(state.equals("3")){
                    status="失败";
                }
                label = new Label(7, i + 1,status + "");
                sheet.addCell(label);
            }
        }
        
        wb.write();
        wb.close();
        return null;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值