码迷,mamicode.com
首页 > 编程语言 > 详细

java直接输出Excel 页面实现下载

时间:2015-04-22 15:12:05      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:

public String excelDomnload() throws Exception{
		try{
			/*
			String path = GlobalKeys.getFunctionConfig("user_attach_save","/opt/tmp/");
			RegUser ru = ((RegUserLoginInfo) request.getSession().getAttribute(GlobalKeys.REG_USER_IN_SESSION_NAME)).getRegUser();
			String tmpPath = File.separator + "import" + File.separator
			+ ru.getName() + File.separator;
			File targetFolder = new File(path, tmpPath);//合并两个路经
			String fName = request.getParameter("fName");
			*/
			response.setContentType("application/msexcel;");			  
			response.setHeader("Content-Disposition", new String(("attachment;filename="+"error.xls").getBytes("GB2312"), "UTF-8"));
			
			File f = new File("d:/20121211165820140_err.xls");
			//File f = new File(targetFolder.getPath()+File.separator+fName);
			FileInputStream in = new FileInputStream(f);
			byte b[] = new byte[1024];
			int i = 0;
			ServletOutputStream out = response.getOutputStream();
			while((i=in.read(b))!=	-1){
				out.write(b, 0, i);
			}
			out.flush();
			out.close();
		    in.close();
		}catch(Exception e){
	        e.printStackTrace();
		}
		return null;
	}

  

java直接输出Excel 页面实现下载

标签:

原文地址:http://www.cnblogs.com/sunxun/p/4447486.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!