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();

           }

  • 相关阅读:
    从运维域看 Serverless 真的就是万能银弹吗?
    C#技术漫谈之垃圾回收机制(GC)(转)
    题解 hdu4624 Endless Spin
    JS递归删除所有子元素【原】
    Asp.Net 生成验证图片
    mouseover显示层mouseout隐藏层,并且在鼠标放上层时显示层【原】
    C# yield关键字的使用
    MS SQL SERVER中的临时表
    猫 老鼠 人的编程题
    面试题:接口和抽象类的区别 【转】
  • 原文地址:https://www.cnblogs.com/rdchen/p/9724049.html
Copyright © 2011-2022 走看看