当前位置: 代码迷 >> Web前端 >> 应用点聚WebOffice在线编辑word
  详细解决方案

应用点聚WebOffice在线编辑word

热度:155   发布时间:2012-10-25 10:58:57.0
使用点聚WebOffice在线编辑word
Word编辑页面
<%@page contentType="text/html;charset=gbk"%>
<%
	String imgpath = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ imgpath;

	String path = (String) request.getAttribute("filepath");
%>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<SCRIPT LANGUAGE=javascript>
<!--
// 初始化控件
function WebOffice1_NotifyCtrlReady() {
	document.all.WebOffice1.OptionFlag |= 128;
	document.all.WebOffice1.LoadOriginalFile("<%=basePath%>/getwordstream.jsp?filename=C:\\1.doc", "doc");
	document.all.WebOffice1.SetToolBarButton2("Standard",1,0);
}

// 上传文档
function SaveDoc(fname,docType) {
	try{
		var webObj=document.getElementById("WebOffice1");
		var returnValue;
		
		webObj.HttpInit();			//初始化Http引擎
		// 添加相应的Post元素 
		webObj.HttpAddPostString("fname", fname);
		webObj.HttpAddPostString("DocType",docType);
		webObj.HttpAddPostCurrFile("DocContent","");		// 上传文件
		returnValue = webObj.HttpPost("<%=basePath%>/savewordstream.jsp");	// 判断上传是否成功
		if("succeed" == returnValue){
			alert("文件上传成功!");	
		}else if("failed" == returnValue)
			alert("文件上传失败!");
		return_onclick();
	}catch(e){
		//alert("异常\r\nError:"+e+"\r\nError Code:"+e.number+"\r\nError Des:"+e.description);
	}
}

// 事件
function WebOffice1_NotifyWordEvent(eventname) {
	if(eventname=="DocumentBeforeSave"){
		//SaveDoc('C:\\1.doc', 'doc');// 此处不能用,否则无法上传, 不知原因
	}
}

//-->
</SCRIPT>

<SCRIPT LANGUAGE=javascript FOR=WebOffice1 EVENT=NotifyCtrlReady>
<!--
 WebOffice1_NotifyCtrlReady();
//-->
</SCRIPT>

<SCRIPT LANGUAGE=javascript FOR=WebOffice1
	EVENT=NotifyWordEvent(eventname)>
<!--
 WebOffice1_NotifyWordEvent(eventname);
//-->
</SCRIPT>

</head>
<body>
	<input type="button" value="保存" onclick="SaveDoc('C:\\1.doc', 'doc')" />
	<!-- 装载Weboffice控件 -->
	<object id=WebOffice1 height='100%'
		style="LEFT: 0px; TOP: 0px; WIDTH: 100%; HEIGHT: 630px"
		classid='clsid:E77E049B-23FC-4DB8-B756-60529A35FAD5'
		codebase='<%=imgpath%>/weboffice_v6.0.5.0.cab#Version=6,0,5,0'>
		<param name='_ExtentX' value='6350'>
		<param name='_ExtentY' value='6350'>
	</object>
	<!--   结束装载代码   -->
</body>
</html>

获取word文件流jsp
<%@page contentType="text/html;charset=gbk"%>
<%@page import="java.io.BufferedInputStream"%>
<%@page import="java.io.FileInputStream"%>

<%
	String filename = request.getParameter("filename");
	filename = new String(filename.getBytes("iso-8859-1"), "utf-8");

	try {
		BufferedInputStream in = new BufferedInputStream(
				new FileInputStream(filename));
		java.io.OutputStream outStream = response.getOutputStream();
		byte[] buf = new byte[1024];
		int bytes = 0;
		while ((bytes = in.read(buf)) != -1)
			outStream.write(buf, 0, bytes);
		in.close();
		outStream.close();
	} catch (Exception e) {
		out.println(e.toString());
	}
%>

保存word文件流jsp
<%@ page contentType="text/html;charset=GB2312"%>
<%@ page import="java.io.*"%>
<jsp:useBean id="mySmartUpload" scope="page"
	class="com.jspsmart.upload.SmartUpload" />
<%
	try {
		// 初始化上传组件
		mySmartUpload.initialize(pageContext);
		mySmartUpload.upload();
		// 获取传到表单记录
		String name = mySmartUpload.getRequest().getParameter("fname");
		com.jspsmart.upload.File myFile = null;
		myFile = mySmartUpload.getFiles().getFile(0);

		if (!myFile.isMissing()) {
			java.io.File tfile = new java.io.File(name);
			if (tfile.exists()) {
				tfile.delete();
			}

			myFile.saveAs(name, mySmartUpload.SAVE_PHYSICAL); // 保存上传文件

			out.clear();
			out.write("succeed");//返回控件HttpPost()方法值。
			out.flush();
		} else
			throw new Exception("File is missing!!");
	} catch (Exception e) {
		out.clear();
		out.write("failed");//返回控件HttpPost()方法值。
		out.flush();
	}
%>


附件说明:
1 js文件夹里面有所需控件
2 所需API文档
1 楼 housheng33 2012-02-06  
你好。我想知道这个点聚用的JDK哪个版本。tomcat的哪个版本呢?
2 楼 tmq3244286 2012-04-01  
我在使用的过程中遇到2个问题:
1,要打开的文件名称含有中文时,会乱码并无法打开;
2,打开WPS文档时文档没有默认最大化;
请问如何解决?
  相关解决方案