首页 新闻 会员 周边 捐助

application/msword导出word文件修改后会生成新的文件夹和文件,要怎样处理

0
悬赏园豆:40 [待解决问题]

68Q_Q68的主页 68Q_Q68 | 初学一级 | 园豆:65
提问于:2011-11-24 12:51
< >
分享
所有回答(1)
-1

是因为word里面包含有图片吧?试试把application/msword换成application/octet-stream;charset=gb2312试试看

LCM | 园豆:6876 (大侠五级) | 2011-11-24 13:05

没有附带图片的word,修改后还是有问题,多生成一个文件夹(立项申请表.files),文件夹中还有2个新文件:1、filelist.xml ; 2、header.htm

支持(0) 反对(0) 68Q_Q68 | 园豆:65 (初学一级) | 2011-11-24 15:57

@68Q_Q68: 那把你怎么导的代码贴上来吧。

支持(0) 反对(0) LCM | 园豆:6876 (大侠五级) | 2011-11-24 16:00

<%@ page language="java" pageEncoding="GBK"%>
<%
 response.addHeader("Content-Type", "application/vnd.ms-word");
 response.addHeader("Content-Type", "application/x-msword");
 String fileName=request.getParameter("fileName")==null?"":request.getParameter("fileName");
 if(fileName.equals("")){
  fileName="word";
 }
 response.addHeader("Content-Disposition", "attachment; filename="+new String(fileName.getBytes(),"ISO-8859-1")+".doc");
 response.addHeader("Expires", "0");
 response.addHeader("Pragma", "cache");
 response.addHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
 String context = "<html xmlns:v=\"urn:schemas-microsoft-com:vml\" " +
      "xmlns:o=\"urn:schemas-microsoft-com:office:office\" " +
      "xmlns:w=\"urn:schemas-microsoft-com:office:word\" " +
      "xmlns=\"http://www.w3.org/TR/REC-html40\"><style>" +
                  "body,tr,td{font-size:12px;} " +
                  ".table_line{padding:3px;border-spacing: 0px;border:1px solid #c9caca; border-collapse:collapse;text-align:center;} " +
                  ".table_line{width:100%;} " +
                  ".tabel_head{background:#e7eef7;height:25px;text-align:center;border-right:1px solid #c9caca;} " +
                  ".table_body{border-top:1px solid #c9caca;border-right:1px solid #c9caca;text-align:center;}</style>";
    context += request.getParameter("sContent");
    context = context.replaceAll("border=0", "border=1");
   // context=context.replaceAll("FONT","img");
    out.println(context);
%>

支持(0) 反对(0) 68Q_Q68 | 园豆:65 (初学一级) | 2011-11-25 12:49

@68Q_Q68: 你把网页一起输出到客户端了,所以才会有那个文件夹出现了。java我不怎么会,我把它改成C#代码以后发现现象和你的差不多。我在最后一行加了句Response.End();以后就正常了。看下C#的代码:

 Response.Clear();
Response.AddHeader("Content-Type", "application/vnd.ms-word");
Response.AddHeader("Content-Type", "application/x-msword");
//String fileName = Request.Params["fileName"] ?? "";
String fileName = "abc";
if (fileName.Equals(""))
{
fileName = "word";
}
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName + ".doc");
Response.AddHeader("Expires", "0");
Response.AddHeader("Pragma", "cache");
Response.AddHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
String context = "<html xmlns:v=\"urn:schemas-microsoft-com:vml\" " +
"xmlns:o=\"urn:schemas-microsoft-com:office:office\" " +
"xmlns:w=\"urn:schemas-microsoft-com:office:word\" " +
"xmlns=\"http://www.w3.org/TR/REC-html40\"><style>" + "body,tr,td{font-size:12px;} " +
".table_line{padding:3px;border-spacing: 0px;border:1px solid #c9caca; border-collapse:collapse;text-align:center;} " +
".table_line{width:100%;} " +
".tabel_head{background:#e7eef7;height:25px;text-align:center;border-right:1px solid #c9caca;} " +
".table_body{border-top:1px solid #c9caca;border-right:1px solid #c9caca;text-align:center;}</style>";
//context += Request.Params["sContent"];
context += "aaaaaaa";
//context = context.Replace("border=0", "border=1");

Response.Write(context);
Response.End();

 

支持(0) 反对(0) LCM | 园豆:6876 (大侠五级) | 2011-11-25 13:41

@LCM: 你看下jsp代码中out有没有close()方法或end()方法,加在后面试一下。out.close();

支持(0) 反对(0) LCM | 园豆:6876 (大侠五级) | 2011-11-25 13:43

@LCM: out有个close方法,调用后还是不行。。并且调用后后台出现异常,不过文件还是能导出。

支持(0) 反对(0) 68Q_Q68 | 园豆:65 (初学一级) | 2011-12-02 09:31
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册