excel 下载模板

来源:互联网 发布:阿里云邮箱书写格式 编辑:程序博客网 时间:2024/04/20 11:38
下载模板
public void importSuccess() throws Exception { 
 try{ 
           HttpServletResponse response = Struts2Utils.getResponse(); 
             //重置响应 
             response.reset(); 
             //设置响应头为二进制流 
             response.setContentType( "application/x-msdownload;charset=utf-8");
   response.setContentType("APPLICATION/OCTET-STREAM "); 
 response.setContentType("application/vnd.ms-excel"); 
 response.setHeader("Content-Disposition", "attachment; filename=Fxcustomer.xls"); 
      
 String path = this.getClass().getClassLoader().getResource("/").getPath();             
     path=path.substring(1,path.length());
             String name = File.separator+path+"Fxcustomer.xls"; 
             logger.info("**********************************"+name+"*******************************");
             
             InputStream is = new FileInputStream(name);           
             HSSFWorkbook wb = new HSSFWorkbook(is); 
            //得到 文件流
            OutputStream out = response.getOutputStream(); 
            wb.write(out);
            is.close();
            out.flush();
            out.close();
   } catch (Exception e) {
    logger.error("下载导出模版失败",e);        
   }
}
原创粉丝点击