[Java] java在web端直接输出Excel实现下载 →→→→→进入此内容的聊天室

来自 , 2021-01-05, 写在 Java, 查看 155 次.
URL http://www.code666.cn/view/a19883fc
  1. public String excelDomnload() throws Exception{
  2.                 try{
  3.                         /*
  4.                         String path = GlobalKeys.getFunctionConfig("user_attach_save","/opt/tmp/");
  5.                         RegUser ru = ((RegUserLoginInfo) request.getSession().getAttribute(GlobalKeys.REG_USER_IN_SESSION_NAME)).getRegUser();
  6.                         String tmpPath = File.separator + "import" + File.separator
  7.                         + ru.getName() + File.separator;
  8.                         File targetFolder = new File(path, tmpPath);//合并两个路经
  9.                         String fName = request.getParameter("fName");
  10.                         */
  11.                         response.setContentType("application/msexcel;");                         
  12.                         response.setHeader("Content-Disposition", new String(("attachment;filename="+"error.xls").getBytes("GB2312"), "UTF-8"));
  13.                        
  14.                         File f = new File("d:/20121211165820140_err.xls");
  15.                         //File f = new File(targetFolder.getPath()+File.separator+fName);
  16.                         FileInputStream in = new FileInputStream(f);
  17.                         byte b[] = new byte[1024];
  18.                         int i = 0;
  19.                         ServletOutputStream out = response.getOutputStream();
  20.                         while((i=in.read(b))!=  -1){
  21.                                 out.write(b, 0, i);
  22.                         }
  23.                         out.flush();
  24.                         out.close();
  25.                     in.close();
  26.                 }catch(Exception e){
  27.                 e.printStackTrace();
  28.                 }
  29.                 return null;
  30.         }
  31. //java/5972

回复 " java在web端直接输出Excel实现下载"

这儿你可以回复上面这条便签

captcha