关于java导出excel文件的问题

zhangmeng0320 2011-11-08 03:00:22
try{
FileOutputStream fout=new FileOutputStream("F:/计算机设备信息");
wb.write(fout);
fout.flush();
fout.close();
}catch(Exception e){
e.printStackTrace();
}

这是一个点击按钮导出excel的任务。
前面代码已经写好,也能导出,但是导出得是本地文件,怎么能导出成直接打开的xls文件??上面代码怎么修改??而且我导出的文件里有乱码怎么解决??
...全文
124 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
wendyzaza 2011-11-10
  • 打赏
  • 举报
回复
关于导出的问题,以上高手的解答了,乱码问题呢,你必须得引用的是apatch 的ant包,不要引用java 的zip ,否则你必须得改api 里 源码,才能解决中文乱码问题。
johnson127 2011-11-10
  • 打赏
  • 举报
回复
HttpServletResponse response = getContext().getResponse();
response.setHeader("Content-disposition", "attachment; filename=print.xls");
BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
wb.write(bos);
bos.flush();
bos.close();
艳沐石 2011-11-09
  • 打赏
  • 举报
回复
try{
// FileOutputStream fout=new FileOutputStream("F:/计算机设备信息");
OutputStream fout = response.getOutputStream(); //使用response的输出流
wb.write(fout);
fout.flush();
fout.close();
}catch(Exception e){
e.printStackTrace();
}
  • 打赏
  • 举报
回复


response.addHeader("Content-Disposition","attachment;filename=xxx.xls");
OutputStream fout = response.getOutputStream(); //使用response的输出流
wb.write(fout);
fout.flush();
fout.close();


敬敬11 2011-11-09
  • 打赏
  • 举报
回复
response.setContentType("application/csv;charset=GB2312");//设置文件格式
String fileName = "list.csv";
response.addHeader("Content-Disposition", "attachment;filename=" + fileName);//设置头部信息
wb.write(fout);

response.setCharacterEncoding("GB2312");//设置编码
response.getOutputStream().flush();
我真的很懒 2011-11-08
  • 打赏
  • 举报
回复
给你个方向,你可以考虑用display
getserved 2011-11-08
  • 打赏
  • 举报
回复
Response.AddHeader( "Content-Disposition ", "inline;filename= " & saveAsFileName)
zhangmeng0320 2011-11-08
  • 打赏
  • 举报
回复
啊啊啊啊啊!!!这么没人气。。。再顶顶,望高手指点
zhangmeng0320 2011-11-08
  • 打赏
  • 举报
回复
在哪儿写这句话??
艳沐石 2011-11-08
  • 打赏
  • 举报
回复
OutputStream os = response.getOutputStream();

输出流,采用这种方式。

当你点击的时候,就会弹出对话框了!
zhangmeng0320 2011-11-08
  • 打赏
  • 举报
回复
求高手指点啊!!!!!!!高手在哪里!!!
zhangmeng0320 2011-11-08
  • 打赏
  • 举报
回复
额。。。。谢了
won1943 2011-11-08
  • 打赏
  • 举报
回复
不知道 忙你顶一下了..

67,515

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧