前置条件:需要一个word模板文档,需要输入文字的地方使用书签站位,书签格式为PO_xxxx
1.引入pageoffice(jsp)
<%@ page language="java"
import="java.util.*,com.zhuozhengsoft.pageoffice.*,com.zhuozhengsoft.pageoffice.wordwriter.*;"
pageEncoding="gb2312"%>
<%@ taglib uri="http://java.pageoffice.cn" prefix="po"%>
2.得到pageoffice、word对象
<%
PageOfficeCtrl poCtrl1 = new PageOfficeCtrl(request);
poCtrl1.setServerPage(request.getContextPath()+"/poserver.zz"); //此行必须
WordDocument doc = new WordDocument();
3.获取word文档的书签并赋值
DataRegion custname = doc.openDataRegion("PO_custname");
custname.setValue(“上海位一信息科技有限公司”);
4.隐藏菜单栏
poCtrl1.setMenubar(false);
5.设置预览时显示的菜单
poCtrl1.addCustomToolButton("另存为", "Show1()", 1);
poCtrl1.addCustomToolButton("全屏/还原", "IsFullScreen", 4);
poCtrl1.addCustomToolButton("刷新", "flash", 5);
poCtrl1.addCustomToolButton("打印", "Print()", 6);
6.设置 PageOfficeCtrl 控件的数据对象
poCtrl1.setWriter(doc);
poCtrl1.webOpen(模板文件的路径, OpenModeType.docNormalEdit, 取一个名称);
7.设置 PageOfficeCtrl 控件是否显示Office工具栏。
poCtrl1.setOfficeToolbars(false);
8.此方法非常重要,在PageOfficeCtrl的后台Java调用代码末尾处必须调用。
poCtrl1.setTagId("PageOfficeCtrl1"); //此行必须
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript">
function Show1() {
document.getElementById("PageOfficeCtrl1").ShowDialog(2);
}
function Save() {
document.getElementById("PageOfficeCtrl1").WebSave();
if(document.getElementById("PageOfficeCtrl1").CustomSaveResult=="ok"){
alert('保存成功!');
location.reload() ;
}else{
alert('保存失败!');
}
}
//全屏/还原
function IsFullScreen() {
document.getElementById("PageOfficeCtrl1").FullScreen = !document.getElementById("PageOfficeCtrl1").FullScreen;
}
function Print() {
document.getElementById("PageOfficeCtrl1").ShowDialog(4);
}
function flash(){
var form = document.getElementById("flashForm");
form.submit();
}
</script>
<link rel="stylesheet" href="/nstyle/css.css" type="text/css">
</head>
<body οnlοad="Print();">
<div style="width:80%; height:700px;position:absolute;z-index:1;" >
<po:PageOfficeCtrl id="PageOfficeCtrl1"></po:PageOfficeCtrl>
</div>
</body>
</html>