zoukankan      html  css  js  c++  java
  • 导出Excel(导出一个模版)

    有时,客户需要一个标准的模板来填东西,然后在导入

    这时可以弄好excel模板,供导出

    /**

         * 导出excel模板文件

         * @param request  

         * @param response

         * @return

         * @throws Exception

         */

        @RequestMapping("downLoadExcelModel")

        @Action(description="导出子表Excel模板文件")

        public void exportExcelMode(HttpServletRequest request,

               HttpServletResponse response) throws Exception{

               String dirPath = FileUtil.getRootPath() + File.separator+"commons" +File.separator+"template"+File.separator+"exportMode"+File.separator;

               String fileName="负荷预测日报表模板.xls";

               ///oms/web/commons/exportMode/负荷预测日报表模板.xls

                FileInputStream inStream = new FileInputStream(new File(dirPath+fileName));

                byte[] buf = new byte[4096]; 

                int readLength; 

                response.setContentType("application/octet-stream;charset=UTF-8");

                response.setHeader("Content-Type","application/vnd.ms-excel");

                response.setHeader( "Content-Disposition", "attachment;filename=" + new String( fileName.getBytes("GB2312"), "8859_1" ));

                response.addHeader("Pargam", "no-cache"); 

                response.addHeader("Cache-Control", "no-cache");

                OutputStream out = response.getOutputStream();   

                while (((readLength = inStream.read(buf)) != -1)) { 

                    out.write(buf, 0, readLength); 

                } 

                inStream.close(); 

                out.flush();   

                out.close();

           }

  • 相关阅读:
    ActionBar Fragment的一个sample activity; 及获取runningAppProcess及跳转
    优化后台推送的service,减少被杀死的几率
    64位win7安装ubunto最新14.04的过程,及出现的问题的解决
    一次非线上iowait高的情况的检查
    一个愚蠢的python逻辑语法错误
    Bellman-Ford算法解决单源最短路问题
    Floyd算法解决多源最短路径问题
    最短路问题Dijkstra算法
    最小生成树之Kruskal算法
    最优二叉搜索树
  • 原文地址:https://www.cnblogs.com/rdchen/p/9724049.html
Copyright © 2011-2022 走看看