zoukankan      html  css  js  c++  java
  • js 导出excel

    function autoDaochu() {
            var url = 'r/mb1/syxExpToExcel.htm';
            var data = {
                name: '1',
                sex: '男'
            }
            var formId = 'a' + new Date().valueOf();
            var html = '<form id="' + formId + '" action="' + url + '" method="post" style="display:none">';
            for (var i in data) {
                html += '<input name="' + i + '" type="text" value="' + data[i] + '"/>';
            }
            html += '</form>';
            $('body').append(html);
            $("#"+formId)[0].submit();
        }

    或者

     //导出excel
            $('#exportBtn').on('click', function () {
                var dataParams = {
                    export_excel: 1,
                    pathname: $('#pathname').val(),
                    date1: $('#date1').val(),
                    date2: $('#date2').val()
                };
                var params = $.param(dataParams);
                var url = '/r/statistics/1002?t=' + new Date().valueOf() + "&" + params;
                $('<form method="post" action="' + url + '"></form>').appendTo('body').submit().remove();
            });

    java 代码

    @RequestMapping(value = "/syxExpToExcel", method = RequestMethod.POST)
        public void expToExcel(HttpServletRequest request, HttpServletResponse response)throws Exception {
            PrintWriter pw=response.getWriter();
            try{
                response.setContentType("application/x-msdownload;charset=gbk");
                response.setCharacterEncoding("UTF-8");
                String fileName =  "11" + ".xls";
                String fileNameTemp = URLEncoder.encode(fileName, "UTF-8");
                response.setHeader("Content-Disposition", "attachment; filename="
                        + new String(fileNameTemp.getBytes("utf-8"), "gbk"));
                OutputStream os = response.getOutputStream();
                //ExcelUtils eu = new ExcelUtils();
                //eu.export(os, "",  legends ,colLength, DbUtils.ListMapToListObject(result),0,0);
                os.flush();
                os.close();
            }catch(Exception e){
                e.printStackTrace();
                pw.print("fail");
            }
        }
  • 相关阅读:
    【论文阅读】A practical algorithm for distributed clustering and outlier detection
    第11组 团队Git现场编程实战
    第11组 团队项目-需求分析报告
    团队项目-选题报告
    第二次结对编程作业
    第11组 团队展示
    第一次结对编程作业
    第一次个人编程作业
    第一次博客作业
    (转)script标签到底该放在哪里
  • 原文地址:https://www.cnblogs.com/lishupeng/p/10508922.html
Copyright © 2011-2022 走看看