在jsp中
response.setContentType("application/x-xls ");
response.setHeader("Content-isposition","inline; attachment;filename=" + filePath);File file = new File(filePath);
if (file.exists()) {
DataOutputStream temps = new DataOutputStream(response.getOutputStream());
DataInputStream in = new DataInputStream(new FileInputStream(filePath));
byte[] b = new byte[2048];
while((in.read(b))!=-1){
temps.write(b);
temps.flush();
}
in.close();
temps.close();
}
} catch(Exception e) {
e.printStackTrace();
}
以上代码 office 2003 excel 能直接在jsp页面打开
但是 office 2007 excel 就开不开 大家有知道的吗?
帮帮忙 谢谢啦!!!!
response.setContentType("application/x-xls ");
response.setHeader("Content-isposition","inline; attachment;filename=" + filePath);File file = new File(filePath);
if (file.exists()) {
DataOutputStream temps = new DataOutputStream(response.getOutputStream());
DataInputStream in = new DataInputStream(new FileInputStream(filePath));
byte[] b = new byte[2048];
while((in.read(b))!=-1){
temps.write(b);
temps.flush();
}
in.close();
temps.close();
}
} catch(Exception e) {
e.printStackTrace();
}
以上代码 office 2003 excel 能直接在jsp页面打开
但是 office 2007 excel 就开不开 大家有知道的吗?
帮帮忙 谢谢啦!!!!
解决方案 »
- js中后一个判断居然在前一个判断结束前执行了
- jsp页面静态化
- 100分求助于高手关于获取三级机构的问题 解决问题马上结帖
- javabean构造函数没有传入参数,对吗?
- ~~~ireport报表工具----如何画非常细(自己定义粗细)的虚线!没有可用分了,求高手帮忙啊。
- 我用RESIN+JSP做的企业信息管理系统出现以下错误 什么原因啊!! 求救
- javabean里scope='application'的问题!请进...
- GIS开发
- 在jsp或servlet中如何恢复框架!!(像这样<frameset cols="80,*">)
- 请问使用什么方法可以关闭当前窗口?
- 关于js问题求助 刚接触 求助各位大侠 望多多指教啊!!
- ireport对分组进行合计的问题
我是在服务器一个文件夹中存放着 xlsx 文件
在IE中 直接打开文件, 那也就是在线打开吧。
office07新建一个文件 这个我用了 一样是开不开的contentType 的问题 能帮我想想是有什么问题吗
try{
if("pdf".equals(format)){
response.setContentType("application/pdf");
}else if ("txt".equals(format)) {
response.setContentType("text/plain;charset=shift-jis");
}else if ("pptx".equals(format)) {
response.setContentType("application/vnd.openxmlformats-officedocument.presentationml.presentation");
}else if ("xlsx".equals(format)) {
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}else if ("docx".equals(format)) {
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
}else if ("dotx".equals(format)) {
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.template");
}else if ("doc".equals(format)) {
response.setContentType("application/msword");
}else if ("xls".equals(format)) {
response.setContentType("application/vnd.ms-excel application/x-excel");
}else if ("pps".equals(format)) {
response.setContentType("application/vnd.ms-powerpoint");
}else if ("ppsx".equals(format)) {
response.setContentType("application/vnd.openxmlformats-officedocument.presentationml.slideshow");
}else {
response.setContentType("application/octet-stream");
}
response.addHeader("Content-Disposition","filename="+sfilename);
FileInputStream fis = new FileInputStream(filePath);
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buffer = new byte[2048];
while (fis.read(buffer) != -1) {
bos.write(buffer);
}
buffer = null;
fis.close();
bos.close();
out.clear();
out = pageContext.pushBody();
}catch (Exception e){
e.printStackTrace();
}
%>
以上是我的全部代码 大家帮忙看看哪个地方有问题呀!!!!
安装一个试试。你是改成这样了吗:response.setContentType("application/vnd.ms-excel");
你给的网址是 office2007免费版下载
我的客户端都安装完了 office2007
response.setContentType("application/vnd.ms-excel");
这个我都适用过了 ,还是不行
再帮忙看看呗 ,到底是哪的问题呢?2003 的 没问题 2007 的就打不开。
刚刚“摆”了一下发现,网上一致认为2003和2007的兼容是个问题,插件也不一定能解决你程序的问题。http://13480.blog.163.com/blog/static/16285514200792525044606/
http://blog.csdn.net/chenzhuolin1002/article/details/6213960
http://hi.baidu.com/274084093/item/11b35f95d1a79dd81a49df6a
http://blog.163.com/rigger21@126/blog/static/9279147200781731014452/
http://download.csdn.net/detail/uixor_/4016423最后一个是别人上传的一个工程,不知道这些搜索能不能有用啊!
用了你的方法还是不好用呀!
现象是 出来一个 打开 保存 的选择
我选择打开 但是出现说我一个action 类什么的
再点 yes 就在IE 中 说我的session 过期什么的
我都没用到session 呀。。
byte b= new byte[1024];
int i=0;
while((i==fis.read(b)) > 0){
os.write(b, 0, i);
out.clear();
out = pageContext.pushBody();
}fis.close();
os.flush();
os.close();
try{
String file = application.getRealPath("/") + "upload\\test.xlsx";
XSSFWorkbook xwb = new XSSFWorkbook(new FileInputStream(file));
//读取第一个sheet
XSSFSheet sheet = xwb.getSheetAt(0); //定义 row、cell
XSSFRow row;
XSSFCell cell;
String output;
int rowNum;
int cellNum; //循环输出表格中的内容
output = "";
rowNum = sheet.getLastRowNum(); for (int i = 0; i <= rowNum; i++)
{
row = sheet.getRow(i);
cellNum = row.getPhysicalNumberOfCells();
for (int j = 0; j < cellNum; j++)
{
cell = row.getCell(j);
output = output + cell.getStringCellValue() + " ";
}
output = output + "<br />";
} out.print(output);}catch(Exception e){
out.print(e.toString());
}%>
try{
String file = application.getRealPath("/") + "upload\\test.xls";
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
HSSFWorkbook xwb = new HSSFWorkbook(fs);
//读取第一个sheet
HSSFSheet sheet = xwb.getSheetAt(0); //定义 row、cell
HSSFRow row;
HSSFCell cell;
String output;
int rowNum;
int cellNum; //循环输出表格中的内容
output = "";
rowNum = sheet.getPhysicalNumberOfRows(); for (int i = 0; i < rowNum; i++)
{
row = sheet.getRow(i);
cellNum = row.getPhysicalNumberOfCells();
for (int j = 0; j < cellNum; j++)
{
cell = row.getCell(j);
output = output + cell.getStringCellValue() + " ";
}
output = output + "<br />";
} out.print(output);}catch(Exception e){
out.print(e.toString());
}%>
<%@page contentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"%>
<%@page import="java.io.*"%>
<%
String filePath = request.getRealPath("/")+"order.xlsx";
System.out.println(filePath);out.clearBuffer();
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.addHeader("Content-Disposition","inline; attachment; filename=" + filePath);File file = new File(filePath);
if (file.exists()) {
OutputStream sout = response.getOutputStream();
InputStream in = new FileInputStream(filePath);
byte[] b = new byte[2048];
int len = 0;
while((len = in.read(b))!=-1){
sout.write(b,0,len);
sout.flush();
}
in.close();
sout.close();
}%>