word文档在线编辑
前台:
需要一个JS来读取cab包中的文件:
var s = "" s += "<object id=WebOffice1 height=768 width='100%'
style='LEFT: 0px; TOP: 0px;display: none;' classid='clsid:E77E049B-23FC-4DB8-B756-60529A35FAD5'
codebase='"+ip+"/oop/assets/tab/script/weboffice_v6.0.4.4.cab#version=6,0,4,4'>"
s +="<param name='_ExtentX' value='6350'><param name='_ExtentY' value='6350'>"
s +="</OBJECT>" document.write(s)
??codebase 处为 cab包服务器端路径
?
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><%String contextPath = request.getContextPath();String ip ="http://" + request.getServerName()+":"+request.getServerPort();request.setAttribute("ip",ip);%><html><head><title>编辑报表模板doc信息</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><meta http-equiv="Pragma" content="no-cache" /><meta http-equiv="Expires" content="-1" /><meta http-equiv="Cache-Control" content="no-cache" /><link rel="stylesheet" href="<%=contextPath %>/assets/common/css/editWord.css" type="text/css"></link><SCRIPT language=javascript event=NotifyToolBarClick(iIndex) for=WebOffice1><!-- WebOffice1_NotifyToolBarClick(iIndex);//--></SCRIPT><script type="text/javascript">window.onload = function(){editDoc();}var ip="${ip}";//修改服务器对应的ip//////////////weboffice在线编辑////////////////////////var id = '${id}';var sc_id='${sc_id}';//在线编辑function editDoc(){var webObj=document.getElementById("WebOffice1");webObj.style.display = 'block';var url=ip+'/oop/tab/method_downFile_tabDepository.action?id='+id+'&sc_id='+sc_id;webObj.LoadOriginalFile(url, "doc");webObj.ShowToolBar = false;}//按钮事件监听function WebOffice1_NotifyToolBarClick(iIndex){if(iIndex==32777){//保存saveDoc();}else if(iIndex==32778){//退出document.all.WebOffice1.FullScreen = false;document.all.WebOffice1.style.display = 'none';}}function SetCustomToolBtn(index,name){document.all.WebOffice1.SetCustomToolBtn(index,name);}//保存到服务器function saveDoc() {var returnValue; // 保存页面的返回值document.all.WebOffice1.HttpInit(); // 初始化Http引擎// 添加相应的Post元素 document.all.WebOffice1.HttpAddPostString("id", id);//添加上传文件 document.all.WebOffice1.HttpAddPostCurrFile("fileupload",""); //提交上传文件 returnValue = document.all.WebOffice1.HttpPost(ip+"/oop/tab/method_saveFile_tabDepository.action");if(returnValue=='保存成功')alert(returnValue);elsealert("保存失败");}//关闭wordfunction closeWord(){var webObj=document.getElementById("WebOffice1");webObj.style.display = 'none'; webObj.CloseDoc(0); }//下载doc文件function downDoc(){var url =projectPath+'/tab/downFile_TabDepository.action?id='+id;}</script><body><div border="0" cellpadding="0" cellspacing="0" onclick="editDoc()">重新加载</button> <button onclick="saveDoc();">保存</button></td></tr><tr><td><FORM name="myform"><script type="text/javascript" src="<%=contextPath %>/assets/tab/script/LoadWebOffice.js"></script></FORM></td></tr></table></div></body>?
?用 edit Doc 方法来获取后台传入的数据流 加载word文档
?
public void downFile() throws Exception {String id = getParameter("id");String sc_id=getParameter("sc_id");String filePath = tabDepositoryService.getWordFile(Long.parseLong(id),sc_id);File file = new File(filePath);InputStream is = new FileInputStream(file);byte[] bytes = new byte[is.available()];is.read(bytes);response.getOutputStream().write(bytes);response.getOutputStream().flush();}?
?action 中调用 Is ?os 输入 word文档 service层只是读取文件路径
?
public void saveFile(String id, String path, File fileupload)throws Exception {PrisonCurInfo pci = iGenericDao.getEntity(PrisonCurInfo.class, Long.parseLong(id));String prisonNum = pci.getPrisonBaseInfo().getPrison_num();path += prisonNum + JYS_DIR+"/";// FileUtil.mkdirs(path);OutputStream os = new FileOutputStream(path + JYS_DOC);InputStream is = new FileInputStream(fileupload);BufferedInputStream bis=new BufferedInputStream(is);BufferedOutputStream bos=new BufferedOutputStream(os);int temp = 0;while ((temp = bis.read()) != -1) {bos.write(temp);}bis.close();bos.flush();bos.close();ConvertUtil.createPDF(path + JYS_DOC, path + JYS_PDF);//转换PDFFile filePdf = new File(path + JYS_PDF);ConvertUtil.changePdfToImg(path + JYS_PDF, path); //转换图片filePdf.delete();new File(path + JYS_DOC).delete();}?保存文件 之后转换为PDF 再转换为 IMG
?
?