zoukankan      html  css  js  c++  java
  • 列表导出至excel

     <button class="btn btn-sm btn-danger" type="button" id="exportBatchBtn">
        <i class="fa fa-trash fa-btn"></i>批量导出
     </button>
       //批量导出
            $("#exportBatchBtn").click(function () {
                var ids = "";
                $(".check").each(function () {
                    if ($(this).prop("checked")) {
                        ids = ids + ($(this).val()) + ","
                    }
                });
                if (ids == "") {
                    top.layer.msg("请选择要导出的数据!");
                    return false;
                } else {
                    ids = ids.substr(0, ids.length - 1);
                    location.href = "<%=basePath%>dispatch/exportByIds?ids="+ids;
                }
            });
        @KrtLog(description = "批量导出发文数据")
        @GetMapping("dispatch/exportByIds")
        public void exportByIds(HttpServletResponse response, String ids, OutputStream os) throws Exception {
            List lists = dispatchFileService.exportByIds(ids);
            //定义导出参数
            ExportParams params = new ExportParams();
            params.setTitle("发文数据");
            Workbook workbook =  ExcelExportUtil.exportExcel(params, Dispatch_export.class, lists);
            String fname = "发文数据"+ DateUtil.dateToString("yyyy-MM-dd", new Date());
            fname = URLEncoder.encode(fname,"UTF-8");
            response.reset();//清空输出流
            response.setCharacterEncoding("UTF-8");//设置相应内容的编码格式
            response.setHeader("Content-Disposition","attachment;filename="+new String(fname.getBytes("UTF-8"),"GBK")+".xls");
            response.setContentType("application/msexcel");//定义输出类型
            //将文件写入输出流
            workbook.write(os);
            workbook.close();
            os.close();
        }
     public List exportByIds(String idsStr){
            List lists = new ArrayList();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
            if (!Assert.isEmpty(idsStr)) {
                String[] ids = idsStr.split(",");
                List<Dispatch> dispatchList = dispatchFileMapper.exportByIds(ids);
                for(int i = 0;i<dispatchList.size();i++) {
                    Dispatch_export export = new Dispatch_export();
                    export.setId(i+1);
                    export.setYear(sdf.format(new Date()));
                    export.setFileTitle(dispatchList.get(i).getFileTitle());
                    export.setName(dispatchList.get(i).getFullName());
                    export.setInsertTime(DateUtil.dateToString("yyyy-MM-dd HH:mm:ss",dispatchList.get(i).getInsertTime()));
                    lists.add(export);
                }
            }
            return lists;
        }
     List exportByIds(String[] ids);
    <select id="exportByIds" parameterType="java.lang.Integer" resultMap="BaseResultMap">
            select
            <include refid="Base_Column_List"/>
            from process_dispatch where id in
            <foreach item="id" collection="array" open="(" separator="," close=")">
                #{id}
            </foreach>
        </select>
  • 相关阅读:
    转:ITIL的開源軟件
    转:Asp.Net大型项目实践
    转:Ubuntu上apache多端口配置虚拟主机的方法
    转:JS 获取鼠标位置
    转:一切整合分享到新浪网易微博代码
    转:Facebook是如何发布代码的
    转:利用 Amazon Web Services 集成企业应用程序使用 Amazon SQS 发送 XML 消息
    sqlite3 常用操作
    转:4 款消息队列软件产品大比拼
    SQL Server 2008 列转行 实例
  • 原文地址:https://www.cnblogs.com/jietz0407-com/p/8430018.html
Copyright © 2011-2022 走看看