• 导出excel 自定义excel名称


    @RequestMapping("/exportVip")
        @ResponseBody
        public void exportVip(HttpServletRequest request, HttpServletResponse response, String time) throws IOException {
    
            //查询需要导出的数据
            List<String> row1 = CollUtil.newArrayList("aa", "bb", "cc", "dd");
            List<String> row2 = CollUtil.newArrayList("aa1", "bb1", "cc1", "dd1");
            List<String> row3 = CollUtil.newArrayList("aa2", "bb2", "cc2", "dd2");
            List<String> row4 = CollUtil.newArrayList("aa3", "bb3", "cc3", "dd3");
            List<String> row5 = CollUtil.newArrayList("aa4", "bb4", "cc4", "dd4");
            List<List<String>> rows = CollUtil.newArrayList(row1, row2, row3, row4, row5);
    
         //设置文件名 String name
    = "购买vip"+time; // 通过工具类创建writer,默认创建xls格式 ExcelWriter writer = ExcelUtil.getWriter(); //合并列,和设置列名 writer.merge(3, "购买vip信息"); // 一次性写出内容,使用默认样式 writer.write(rows);
         //自定义标题别名
         writer.addHeaderAlias("phoneNum", "手机号");
         writer.addHeaderAlias("userNickName", "用户昵称");
         writer.addHeaderAlias("vipName", "会员名称");
         writer.addHeaderAlias("money", "会员价格");
         writer.addHeaderAlias("createTime", "购买时间");
         writer.addHeaderAlias("vipOverTime", "会员到期时间");
    //out为OutputStream,需要写出到的目标流
            //response为HttpServletResponse对象
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            //test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
            response.setHeader("Content-Disposition", "attachment;filename=" + new String(name.getBytes(), "iso-8859-1") + ".xls");
            response.setHeader("Pragma", "no-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0);
            ServletOutputStream out = response.getOutputStream();
            writer.flush(out);
            // 关闭writer,释放内存
            writer.close();
        }


    页面跳转方式
    //导出购买vip的人员
    $("#exportVip").click(function () {
    var time = $("#test3").val();
    window.location.href = "/bg/statistics/exportVip?time" + time;
    })


  • 相关阅读:
    MySQL中的MRR和BKA
    MySQL中的BNL优化器
    MySQL中索引
    MySQL中的两种排序方式: index和filesort
    设计模式之观察者模式
    设计模式之策略模式
    设计模式之模板方法
    java和JavaScript的区别
    HTML 简介--from app (W3)
    与代码同行-五年计划
  • 原文地址:https://www.cnblogs.com/SeaWxx/p/8482069.html
Copyright © 2020-2023  润新知