JSP如何显示word文件内容啊

mxx123 2009-10-16 02:57:45
如何才能实现,在JSP页面指定位置上,将服务器上指定目录下的word文件里的内容原样(原格式)显示出来啊?
word里有表格和文字。
要求,直接显示,而不通过设置打开或保存对话框。
直接输入像这样的地址:HTTP://路径/test.doc,会弹出对话框让选择打开或保存,所以不要告诉我用这样的方法。
用iframe src='路径/test.doc',我也试过,结果报404错误。
...全文
1572 26 打赏 收藏 转发到动态 举报
写回复
用AI写文章
26 条回复
切换为时间正序
请发表友善的回复…
发表回复
hxzhh 2011-11-22
  • 打赏
  • 举报
回复
我也需要
ydcsh 2010-01-22
  • 打赏
  • 举报
回复
感觉不一定行吧?
水中影子 2009-10-17
  • 打赏
  • 举报
回复
留个脚印,学习了。。。
zl3450341 2009-10-16
  • 打赏
  • 举报
回复
纯操作excel的话

还是建议用jxl



使用JXL 读取Excel合并单元格方法

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import jxl.Range;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class ReadExcel {
public ReadExcel(){

}
public void readExcel(String filepath){
try {
InputStream is = new FileInputStream(filepath);
Workbook wb = Workbook.getWorkbook(is);
int sheet_size = wb.getNumberOfSheets();
for(int index = 0; index < sheet_size ; index++){
Sheet sheet = wb.getSheet(index);
Range[] ranges = sheet.getMergedCells();
System.out.println("sheet" + index + "包含" + ranges.length + "个区域");
for(Range space:ranges){
System.out.print(space.getTopLeft().getRow()+1+"行,");
System.out.print(space.getTopLeft().getColumn()+1+"列\t");
System.out.print(space.getBottomRight().getRow()+1+"行,");
System.out.print(space.getBottomRight().getColumn()+1+"列\n");
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (BiffException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}

mxx123 2009-10-16
  • 打赏
  • 举报
回复

像这样的有合并单元格的,如何用POI来读取excel里的数据读出来后,保存到SqlServer啊?
ddshuaige 2009-10-16
  • 打赏
  • 举报
回复
不过,我用的ie7,又弹出打开,保存,取消的提示框。
ddshuaige 2009-10-16
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 mxx123 的回复:]
引用 4 楼 ddshuaige 的回复:
<%@ page contentType="application/msword;charset=gb2312" %>

<%
File f=new File("D:/Tomcat 5.5/webapps/neiwang/txt/telephone.doc");
FileInputStream fin=new FileInputStream(f);
OutputStream output=response.getOutputStream();
byte[] buf=new byte[1024];
int r=0;
response.setContentType("application/msword;charset=GB2312");
while((r=fin.read(buf,0,buf.length))!=-1)
{
output.write(buf,0,r);//response.getOutputStream()
}
fin.close();
output.close();
%>


这个能否按照原来的格式显示啊?如果word里有表格等元素,还能否现实啊?
另外我想通过action来实现啊。
[/Quote]
可以按照原来显示,也可以显示表格。
通过action也可以输出。

lvkai0452 2009-10-16
  • 打赏
  • 举报
回复
用微软的dsoframer控件就可以的
sunnyfun888 2009-10-16
  • 打赏
  • 举报
回复
或许应该换个思路,把word文件转为html,调用收费的ms office,免费的openoffice都可以做到这点

POI对表格或者图表貌似有兼容问题
mxx123 2009-10-16
  • 打赏
  • 举报
回复
另外问个问题,jsp如何把excel里的数据读出后保存到SqlServer里啊?
如果用POI来做,需要哪些JAR包啊?那些JAR包要去哪里下载啊?
NOKIA5320XM 2009-10-16
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 ddshuaige 的回复:]
<%@ page contentType="application/msword;charset=gb2312" %>

<%
File f=new File("D:/Tomcat 5.5/webapps/neiwang/txt/telephone.doc");
FileInputStream fin=new FileInputStream(f);
OutputStream output=response.getOutputStream();
byte[] buf=new byte[1024];
int r=0;
response.setContentType("application/msword;charset=GB2312");
while((r=fin.read(buf,0,buf.length))!=-1)
{
output.write(buf,0,r);//response.getOutputStream()
}
fin.close();
output.close();
%>

[/Quote]
在我的机子上,全都是乱码,不能按照原来的格式显示
louisgarcia 2009-10-16
  • 打赏
  • 举报
回复
不知道SSI能不能行
lzh_me 2009-10-16
  • 打赏
  • 举报
回复
推荐使用FCKeditor文本编辑程序,功能强大跟微软office软件一样的功能。

不知道能不能满足lz的需求。
mxx123 2009-10-16
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 ddshuaige 的回复:]
<%@ page contentType="application/msword;charset=gb2312" %>

<%
File f=new File("D:/Tomcat 5.5/webapps/neiwang/txt/telephone.doc");
FileInputStream fin=new FileInputStream(f);
OutputStream output=response.getOutputStream();
byte[] buf=new byte[1024];
int r=0;
response.setContentType("application/msword;charset=GB2312");
while((r=fin.read(buf,0,buf.length))!=-1)
{
output.write(buf,0,r);//response.getOutputStream()
}
fin.close();
output.close();
%>

[/Quote]
这个能否按照原来的格式显示啊?如果word里有表格等元素,还能否现实啊?
另外我想通过action来实现啊。
ABAP1314 2009-10-16
  • 打赏
  • 举报
回复
试过 JSP 转 Word 文件, 在JSP 页面 头标签有的。。。

读取也应该有吧 你找找
老猫的TOM 2009-10-16
  • 打赏
  • 举报
回复
我没有做过这种但是考虑到楼主想要保持word文件在jsp显示的数据格式完全一致,我想可不可以利用dsoframer中间件直接在jsp中嵌入word,这样利用读取方式能够显示,不知道可去不可取,还望楼主定夺
liwenso 2009-10-16
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 ddshuaige 的回复:]
<%@ page contentType="application/msword;charset=gb2312" %>

<%
File f=new File("D:/Tomcat 5.5/webapps/neiwang/txt/telephone.doc");
FileInputStream fin=new FileInputStream(f);
OutputStream output=response.getOutputStream();
byte[] buf=new byte[1024];
int r=0;
response.setContentType("application/msword;charset=GB2312");
while((r=fin.read(buf,0,buf.length))!=-1)
{
output.write(buf,0,r);//response.getOutputStream()
}
fin.close();
output.close();
%>

[/Quote]


还是这个方便,直接servlet输出
jwtigerqwe 2009-10-16
  • 打赏
  • 举报
回复
哇 学习了
ddshuaige 2009-10-16
  • 打赏
  • 举报
回复
<%@ page contentType="application/msword;charset=gb2312" %>

<%
File f=new File("D:/Tomcat 5.5/webapps/neiwang/txt/telephone.doc");
FileInputStream fin=new FileInputStream(f);
OutputStream output=response.getOutputStream();
byte[] buf=new byte[1024];
int r=0;
response.setContentType("application/msword;charset=GB2312");
while((r=fin.read(buf,0,buf.length))!=-1)
{
output.write(buf,0,r);//response.getOutputStream()
}
fin.close();
output.close();
%>
liwenso 2009-10-16
  • 打赏
  • 举报
回复
servlet读取word输出流到jsp
jsp头上加
<%@page contentType="application/msword;charset=GBK" %>
加载更多回复(2)

67,513

社区成员

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

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