pageoffice
一、选择文件打开
1.postup.exe安装
2.导入jar包:pageoffice.jar
理论上不需要印章功能下面两个不需要导入,我只用到了第一个jar包,用于导出word文档在线编辑并保存.
3.再web.xml中添加下面代码:
<!-- PageOffice Begin -->
<servlet>
<servlet-name>poserver</servlet-name>
<servlet-class>com.zhuozhengsoft.pageoffice.poserver.Server</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>poserver</servlet-name>
<url-pattern>/poserver.zz</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>poserver</servlet-name>
<url-pattern>/sealsetup.exe</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>poserver</servlet-name>
<url-pattern>/posetup.exe</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>poserver</servlet-name>
<url-pattern>/pageoffice.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>poserver</servlet-name>
<url-pattern>/jquery.min.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>poserver</servlet-name>
<url-pattern>/pobstyle.css</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>adminseal</servlet-name>
<servlet-class>com.zhuozhengsoft.pageoffice.poserver.AdminSeal</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>adminseal</servlet-name>
<url-pattern>/adminseal.zz</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>adminseal</servlet-name>
<url-pattern>/loginseal.zz</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>adminseal</servlet-name>
<url-pattern>/sealimage.zz</url-pattern>
</servlet-mapping>
<mime-mapping>
<extension>mht</extension>
<mime-type>message/rfc822</mime-type>
</mime-mapping>
<context-param>
<param-name>adminseal-password</param-name>
<param-value>111111</param-value>
</context-param>
<!-- PageOffice End -->
4.这里修改成您的印章简易管理页的管理员登录密码,为了安全,强烈建议修改!!!
如果您用的是默认的Access数据库,下面节点不用修改,继续保持被注释状态或直接删除。 如果您用的是Oracle、MySQL等其他数据库,请将下面节点的注释去掉,并且修改成您的印章数据库连接参数。最好把WEB-INF\lib下的seal.mdb也删除掉。
<context-param>
<param-name>posealdb-driver</param-name>
<param-value>oracle.jdbc.driver.OracleDriver</param-value>
</context-param>
<context-param>
<param-name>posealdb-url</param-name>
<param-value>jdbc:oracle:thin:@192.168.0.1:1521:orcl</param-value>
</context-param>
<context-param>
<param-name>posealdb-username</param-name>
<param-value>system</param-value>
</context-param>
<context-param>
<param-name>posealdb-password</param-name>
<param-value>111111</param-value>
</context-param>
5.调用pageoffice需要在jsp中加入下面代码:
<script type="text/javascript" src=" jquery.min.js"></script>
<script type="text/javascript" src=" pageoffice.js" id="po_js_main"></script>
注意:由于再 准备3 中已经再web.xml中配置了pageoffice.js和jquery.min.js,所以此处无需将js文件放入webapp目录下
6.index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"><
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--PageOffice.js和jquery.min.js文件一定要引用-->
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="pageoffice.js" id="po_js_main"></script>
</head>
<body>
<div style="text-align:center;">
<b>在线编辑</b><br>
<a href="javascript:POBrowser.openWindowModeless('openword' , 'width=1200px;height=800px;');">word测试</a><br>
</div>
</body>
</html>
7.word.jsp
<%@ page language="java"
import="java.util.*,com.zhuozhengsoft.pageoffice.*"
pageEncoding="utf-8"%>
<%@ taglib uri="http://java.pageoffice.cn" prefix="po" %>
<%
PageOfficeCtrl poCtrl = (PageOfficeCtrl)request.getAttribute("poCtrl");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<form id="form1" >
<div style="width:auto; height:700px;">
<%=poCtrl.getHtmlCode("PageOfficeCtrl1")%>
</div>
</form>
<script src="js/assets/global/plugins/jquery.min.js"
type="text/javascript"></script>
<script src="js/serviceJs/xtgl/word.js" charset="UTF-8"></script>
<!-- END PAGE LEVEL SCRIPTS -->
<script>
//隐藏标题栏
document.getElementById("PageOfficeCtrl1").Titlebar = false;
//隐藏菜单栏
document.getElementById("PageOfficeCtrl1").Menubar = false;
function importWord() {
document.getElementById("PageOfficeCtrl1").WordImportDialog();
}
//Excel打开
function ExcelImportDialog() {
document.getElementById("PageOfficeCtrl1").ExcelImportDialog();
}
//保存
function SaveDocument() {
document.getElementById("PageOfficeCtrl1").WebSave();
}
//打印
function ShowPrintDlg() {
document.getElementById("PageOfficeCtrl1").ShowDialog(4); //打印对话框
}
//全屏
function SwitchFullScreen() {
document.getElementById("PageOfficeCtrl1").FullScreen = !document.getElementById("PageOfficeCtrl1").FullScreen;
}
//關閉
function CloseFile(){
window.external.close();
}
function ShowDefineDataTags() {
document.getElementById("PageOfficeCtrl1").ShowHtmlModelessDialog("dataRegionDlg", "parameter=xx", "left=300px;top=390px;width=520px;height=410px;frame:no;");
}
//获取后台定义的Tag 字符串
function getTagNames() {
var tagNames = document.getElementById("PageOfficeCtrl1").defineTagNames;
return tagNames;
}
//定位Tag
function locateTag(tagName) {
var appSlt = document.getElementById("PageOfficeCtrl1").Document.Application.Selection;
var bFind = false;
//appSlt.HomeKey(6);
appSlt.Find.ClearFormatting();
appSlt.Find.Replacement.ClearFormatting();
bFind = appSlt.Find.Execute(tagName);
if (!bFind) {
document.getElementById("PageOfficeCtrl1").Alert("已搜索到文档末尾。");
appSlt.HomeKey(6);
}
window.focus();
}
//添加Tag
function addTag(tagName) {
try {
var tmpRange = document.getElementById("PageOfficeCtrl1").Document.Application.Selection.Range;
tmpRange.Text = tagName;
tmpRange.Select();
return "true";
} catch (e) {
return "false";
}
}
//删除Tag
function delTag(tagName) {
var tmpRange = document.getElementById("PageOfficeCtrl1").Document.Application.Selection.Range;
if (tagName == tmpRange.Text) {
tmpRange.Text = "";
return "true";
}
else
return "false";
}
</script>
</body>
</html>
8.Controller
@RequestMapping("openword")
public String openword(HttpServletRequest request, HttpServletResponse response) {
WordDocument doc = new WordDocument();
doc.getTemplate().defineDataTag("{ 甲方 }");
doc.getTemplate().defineDataTag("{ 乙方 }");
PageOfficeCtrl poCtrl=new PageOfficeCtrl(request);
poCtrl.setServerPage(request.getContextPath()+"/poserver.zz");//设置服务页面
poCtrl.addCustomToolButton("Word","importWord()",13);//添加自定义保存按钮
poCtrl.addCustomToolButton("Excel","ExcelImportDialog()",13);//添加自定义保存按钮
poCtrl.addCustomToolButton("定义数据区域", "ShowDefineDataTags()", 20);
poCtrl.addCustomToolButton("保存", "SaveDocument()", 1);
poCtrl.addCustomToolButton("打印", "ShowPrintDlg()", 6);
poCtrl.addCustomToolButton("-", "", 5);
poCtrl.addCustomToolButton("全屏切换", "SwitchFullScreen()", 4);
poCtrl.addCustomToolButton("关闭", "CloseFile()", 21);
//设置保存页面
poCtrl.setSaveFilePage("savefile");
poCtrl.setTagId("PageOfficeCtrl1"); //此行必须
poCtrl.setTheme(ThemeType.Office2007);
poCtrl.setBorderStyle(BorderStyleType.BorderThin);
poCtrl.setWriter(doc);
request.setAttribute("poCtrl", poCtrl);
return "BasicInformation/openDocument";
}
//文件保存
@RequestMapping("savefile")
public void savefile(HttpServletRequest request, HttpServletResponse response){
FileSaver fs = new FileSaver(request, response);
fs.saveToFile(request.getSession().getServletContext().getRealPath("doc/") + "/" + fs.getFileName());
fs.close();
}
二、数据回显
1.js调用文件
POBrowser.openWindowModeless('openfile?id='+aData.num,'width=1200px;height=800px;');
2.openfile.jsp
<%@ page language="java"
import="java.util.*,com.zhuozhengsoft.pageoffice.*,com.zhuozhengsoft.pageoffice.wordwriter.*"
pageEncoding="utf-8"%>
<%@ taglib uri="http://java.pageoffice.cn" prefix="po" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>审计通知书模板</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<div style=" width:auto; height:700px;">
<po:PageOfficeCtrl id="PageOfficeCtrl1" />
</div>
<script type="text/javascript">
function Save() {
document.getElementById("PageOfficeCtrl1").WebSave();
}
</script>
</body>
</html>
3.controller文件
@RequestMapping(value = "openfile")
public String openfile(HttpServletRequest request, String id) {
AUDIT_PNOTICE_MB mb = noticeService.getSjtzsByNum(id);
String suffix = mb.getName().substring(mb.getName().lastIndexOf(".") + 1);
String filePath = AddressUtil.getUpload_address() + "\\" + Constants.PATH_TZMB
+ "\\" + mb.getNum()+"."+suffix;
PageOfficeCtrl poCtrl=new PageOfficeCtrl(request);
poCtrl.setServerPage(request.getContextPath() + "/poserver.zz");//设置授权程序servlet
poCtrl.setTitlebar(false); //隐藏标题栏
poCtrl.setMenubar(false); //隐藏菜单栏
poCtrl.setOfficeToolbars(false);//隐藏Office工具条
poCtrl.setCustomToolbar(false);
if ("DOC".equals(suffix.toUpperCase()) || "DOCX".equals(suffix.toUpperCase())) {
poCtrl.webOpen(filePath,OpenModeType.docReadOnly,"张三");//D:\\UploadFiles\\22.docx
}else {
poCtrl.webOpen(filePath,OpenModeType.xlsReadOnly,"张三");
}
poCtrl.setTagId("PageOfficeCtrl1"); //此行必须
return "BasicInformation/openfile";
}
数据区域
dataRegionDlg.jsp
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<style type="text/css">
#tagTable td{ height:25px; border-bottom:dotted 1px gray;}
</style>
<script type="text/javascript">
// 方法: window.external.CallParentFunc
// 作用: 调用父窗口中的js函数, 目前只支持传递一个参数.
var names = window.external.CallParentFunc("getTagNames", "");
alert(names)
var tagArr = names.split(";");
//首次加载数据
function load() {
searchBookMark('');
return;
}
//加载数据列表
function searchBookMark(s) {
//删除所有行
var tb1 = document.getElementById("tagTable");
var rCount = tb1.rows.length;
for (var i = 0; i < rCount; i++) {
tb1.deleteRow(0);
}
var oTable = document.getElementById("tagTable");
for (var i = 0; i < tagArr.length; i++) {
if (tagArr[i] != null && tagArr[i] != "" && 0 == tagArr[i].toLocaleLowerCase().indexOf(s.toLocaleLowerCase())) {
var oTr = oTable.insertRow();
var oTd = oTr.insertCell();
oTd.innerHTML = tagArr[i];
oTd = oTr.insertCell();
oTd.innerHTML = " <a href=\"javascript:void(0);\" onclick= \"add('" + tagArr[i] + "','aaaa')\"> 添加</a>";
oTd = oTr.insertCell();
oTd.innerHTML = " <a href=\"javascript:void(0);\" onclick= \"locate('" + tagArr[i] + "')\"> 定位</a>";
oTd = oTr.insertCell();
oTd.innerHTML = " <a href=\"javascript:void(0);\" onclick= \"del('" + tagArr[i] + "')\"> 删除</a>";
}
}
}
function Button1_onclick() {
var s = document.getElementById("Text1").value.toLocaleLowerCase();
var tb1 = document.getElementById("tagTable");
var rCount = tb1.rows.length;
for (var i = 0; i < rCount; i++) {
tb1.deleteRow(0);
}
var oTable = document.getElementById("tagTable");
for (var i = 0; i < tagArr.length; i++) {
if (tagArr[i] != null && tagArr[i] != "" && tagArr[i].toLocaleLowerCase().indexOf(s) >= 0) {
var oTr = oTable.insertRow();
var oTd = oTr.insertCell();
oTd.innerHTML = tagArr[i];
oTd = oTr.insertCell();
oTd.innerHTML = " <a href=\"javascript:void(0);\" onclick= \"add('" + tagArr[i] + "')\"> 添加</a>";
oTd = oTr.insertCell();
oTd.innerHTML = " <a href=\"javascript:void(0);\" onclick= \"locate('" + tagArr[i] + "')\"> 定位</a>";
oTd = oTr.insertCell();
oTd.innerHTML = " <a href=\"javascript:void(0);\" onclick= \"del('" + tagArr[i] + "')\"> 删除</a>";
}
}
}
//******** Tag 操作 ************************************************************
function add(name) {
if ("true" == window.external.CallParentFunc("addTag", name)) {
}
}
function del(name) {//alert(name);
if ("false" == window.external.CallParentFunc("delTag", name)) {
alert("请先执行\"定位\"操作,然后再删除。");
}
}
function locate(name) {
window.external.CallParentFunc("locateTag", name);
}
</script>
</head>
<body>
<div style="width: 380px; height: 320px;">
<div style="float: left;font-size:12px;">
<span>待添加数据标签:</span><br />
<input id="Text1" type="text" onpropertychange="searchBookMark(this.value);" oninput="searchBookMark(this.value);" />
<input id="Button1" type="button" value="搜索" onclick="return Button1_onclick()" />
<div style="width: 380px; height: 300px; border: solid 1px #ccc; overflow-y: scroll; ">
<table id="tagTable" style=" font-size:12px;">
</table>
</div>
</div>
</div>
</body>
<script type="text/javascript">
load();
//alert(2);
</script>
</html>