支持的浏览器:主要是IE浏览器,不支持谷歌 火狐
使用条件:需要安装微软的WPS(最好2007及以上的)
操作步骤:
下载dsoframer.ocx 控件
操作:将DSOFramer.ocx复制到C:\windows\system32目录下,
开始->运行->regsvr32 DSOFramer.ocx , 系统会提示DSOFramer.ocx中的DllRegisterServer成功
注册成功后就可以使用了
// dsoframer.ocx 的使用 JSP部分
classid="clsid:00460182-9E5E-11D5-B7C8-B8269041DD57" codebase="dsoframer.ocx#version=2.3.0.1">
//codebase="dsoframer.ocx#version=2.3.0.1" 这个是你的控件的版本:自己查看属性就可以看到
// dsoframer.ocx 的使用jq部分打开
//获得服务器的地址
function getRootPath(){
//获取当前网址,如: http://localhost:8083/proj/meun.jsp
var curWwwPath = window.document.location.href;
//获取主机地址之后的目录,如: proj/meun.jsp
var pathName = window.document.location.pathname;
var pos = curWwwPath.indexOf(pathName);
//获取主机地址,如: http://localhost:8083
var localhostPath = curWwwPath.substring(0, pos);
//获取带"/"的项目名,如:/proj
var projectName = pathName.substring(0, pathName.substr(1).indexOf('/')+1);
return localhostPath+projectName;
}
function getWord() {
try {
var serverPath=this.getRootPath()+"/AffixFiles/Offices/"+fileName;
//根据文件服务器路径判断服务器文件是否存在
$.ajax(serverPath, {
type: 'get',
timeout: 1000,
success: function() {
document.all.FramerControl1.Open(serverPath, false, "Word.Document");
},
error: function() {
document.all.FramerControl1.CreateNew("Word.Document");
}
});
}
// dsoframer.ocx 的使用jq部分 保存
function saveWord() {
document.all.FramerControl1.HttpInit();
document.all.FramerControl1.HttpAddPostCurrFile("files", fileName);
document.all.FramerControl1.HttpPost("../../../system/printReportAction_fileUploadOffice.do");
//这里参数是你的action的地址
}
//JAVA ACTTION 部分(action的配置我就不详细说了)
// 用户上传的文件 这里名字需document.all.FramerControl1.HttpAddPostCurrFile("files", fileName);
里面的第一参数相同
private File[] files;
// filesFileName 必须是前面files是与上面相同fileName是固定的
private String[] filesFileName; // 上传文件的文件名
private String[] filesContentType;// 上传文件的类型
/**
* fileUploadOffice Office文件在线保存
*/
public void fileUploadOffice(){
//判断是否有文件上传
if(getWriter() == false)return;
String exescmd = request.getParameter("execscmd");
String sSavePath = request.getRealPath("/AffixFiles\\Offices") + "/".replace("\\", "/");
FileUploadServer.fileUploadOffice(getFiles(),getFilesFileName(),sSavePath,
exescmd);
/*try {
out=response.getWriter();
out.write(outStr);
} catch (IOException e) {
e.printStackTrace();
}finally{
out.close();
}*/
}
/*属性的getter和setter办法 */
public File[] getFiles() {
return files;
}
public void setFiles(File[] files) {
this.files = files;
}
public String[] getFilesFileName() {
return filesFileName;
}
public void setFilesFileName(String[] filesFileName) {
this.filesFileName = filesFileName;
}
public String[] getFilesContentType() {
return filesContentType;
}
public void setFilesContentType(String[] filesContentType) {
this.filesContentType = filesContentType;
}
我在搞这个的时候主要遇到两个问题:一个是没法保存到服务器(没有跳转到action)可以保存到本地:我当时是因为使用的是WPS2003换成2010的就支持了,第二个是文件没传过去,原因主要是因为
// 用户上传的文件 这里名字需document.all.FramerControl1.HttpAddPostCurrFile("files", fileName);
里面的第一参数相同
private File[] files;
// filesFileName 必须是前面files是与上面相同fileName是固定的
这两个参数对应问题的问题
这个方法document.all.FramerControl1.HttpAddPostCurrFile("files", fileName); 其实就是模拟一个form表单 里面有个