您当前的位置: 首页 >  Java

小志的博客

暂无认证

  • 0浏览

    0关注

    1217博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

java下载excel模板文件例子

小志的博客 发布时间:2018-12-29 11:45:09 ,浏览量:0

     import org.springframework.http.ResponseEntity;
     import org.springframework.http.HttpHeaders;
     import org.springframework.http.HttpStatus;
     import org.springframework.http.MediaType;
     import javax.servlet.http.HttpServletRequest;
     import javax.servlet.http.HttpServletResponse;
     import org.apache.commons.io.FileUtils;

     @RequestMapping(value = "/downLoadmoban",method = RequestMethod.GET)
	  public ResponseEntity downLoadmoban(HttpServletRequest request, HttpServletResponse response) throws IOException{
			String rootpath = request.getSession().getServletContext().getRealPath("/muban");//获取项目中的模板文件夹
			File file=new File(rootpath + File.separator + "ceshi.xls");  
			HttpHeaders headers = new HttpHeaders();    
			String fileName=new String("测试统计表导入模板.xls".getBytes("gb2312"),"iso-8859-1");//为了解决中文名称乱码问题  
			headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);  
			headers.set(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"");  
			return new ResponseEntity(FileUtils.readFileToByteArray(file),    
					headers, HttpStatus.OK);    
	  }
关注
打赏
1661269038
查看更多评论
立即登录/注册

微信扫码登录

0.0408s