jxl的问题!如何把生成的excel传到客户端自动打开!!!

chtfallcn 2004-08-17 01:08:45
我用jxl生成了一个excel表,如何才能实现在客户端自动打开excel显示这个表?
请大家帮帮忙,最好提供下这方面的资料!
...全文
399 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
liufangli3639 2010-06-09
  • 打赏
  • 举报
回复
我晕哦,是2004年的帖子啊,我几年后还来回复
liufangli3639 2010-06-09
  • 打赏
  • 举报
回复
我也遇到了和你相同的问题,我是这么打开的:
Runtiem.getRuntime().exec("cmd /c start "+path);
要主要命令的空格哦,一个都不能少
sheng_long 2004-08-18
  • 打赏
  • 举报
回复
我这个是下载excel文件用的
fileName是下载时给客户端显示的文件名
fileName包括文件的后缀名
如果遵照excel的格式的文件
是可以直接用excel程序打开的
chtfallcn 2004-08-18
  • 打赏
  • 举报
回复
to : sheng_long(sheng_long

你这种方法是不是在客户端把excel文件从服务器下载到客户端?
下载后能自动调用excel程序打开这个文件么?
还有,filename的值有没有什么限制,能不能加上路径名啊?
sheng_long 2004-08-18
  • 打赏
  • 举报
回复
resp.setHeader("Content-disposition","attachment; filename=" + fileName);
fileName是下载的文件名称。
fanciex 2004-08-18
  • 打赏
  • 举报
回复
直接一个超链接
chtfallcn 2004-08-18
  • 打赏
  • 举报
回复
用jxl.jar的输出流能够实现:
客户端接收输出流,然后自动调用excel程序把表格显示出来(excel嵌入到ie或者纯粹电子表格的形式都可以)。实现这个结果需要在http头中进行一些设置。
请问各位大虾,这个http头应该怎么设置,最好给个例子,小弟初学jsp,请多指教。
分不够可以加哈!!!
sheng_long 2004-08-18
  • 打赏
  • 举报
回复
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
OutputStream out = null;
int length = 0;
try {
out = resp.getOutputStream();
//kk是传入的下载内容
String kk = "\"adasd\"\",asdasd\",\"asdasdasd\"";
byte[] bString = kk.getBytes();
int len = 0;
length = bString.length;
resp.setContentType("application/x-msdownload");
String fileName = "test.xls";
resp.setHeader(
"Content-disposition",
"attachment; filename=" + fileName);
while (len < length) {
int remainedLen = length - len;
if (remainedLen > 1024){
remainedLen = 1024;
}
out.write(bString, len, remainedLen);
out.flush();
len = len + remainedLen;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (out != null) {
out.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
chtfallcn 2004-08-18
  • 打赏
  • 举报
回复
to : sheng_long

filename需要是什么格式啊?
d:\tomcat\cht.xls 还是cht.xls ?就是可不可以带文件的路径名

需要引入某个类么?还是要在http头设置一下,最好给个例子,谢谢!
chtfallcn 2004-08-18
  • 打赏
  • 举报
回复
to : sheng_long
你说的程序直接加入页面代码里就可以么?我直接加进去了,但是出现编译错误,如下:

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 102 in the jsp file: /machine/ecxel.jsp

Generated servlet error:
[javac] Compiling 1 source file

D:\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\machine\ecxel_jsp.java:146: cannot resolve symbol
symbol : variable resp
location: class org.apache.jsp.machine.ecxel_jsp
resp.setHeader("Content-disposition","attachment; filename=" + request.getParameter("name_excle"));

是不是还要加入什么类啊???谢谢
chtfallcn 2004-08-17
  • 打赏
  • 举报
回复
怎么没人啊???
自己顶一下!!!
chtfallcn 2004-08-17
  • 打赏
  • 举报
回复
我的意思不是在网页上显示出来excel表。
我做的网页上有个导入excel按钮,我是想一点击按钮就能够在客户端自动打开excel程序,显示出网页上的数据(从数据库中读取出来的数据)
请问怎样才能够实现???
是不是和http信息头有关系?最好能给个例子,或者相关的资料!!!
wushuren 2004-08-17
  • 打赏
  • 举报
回复
对,
<%@ page contentType="application/vnd.ms-excel"%>
caoxmby 2004-08-17
  • 打赏
  • 举报
回复
设置response的content type 为 application/vnd.ms-excel 试试

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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