1.前置条件
需要一个word模板文件,在变量的地方设置书签。书签格式为PO_x,
2.引入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"%>
3.PageOfficeCtrl poCtrl1 = new PageOfficeCtrl(request); //通过request得到pageoffice对象
poCtrl1.setServerPage(request.getContextPath()+"/poserver.zz"); //此行必须
WordDocument doc = new WordDocument();//new 一个word对象
4.DataRegion custname = doc.openDataRegion("PO_custname");//得到标签名为PO_custname的可输入文本区域,
custname.setValue(“上海位一信息技术有限公司”);//给此区域赋值。
5.poCtrl1.setMenubar(false);//隐藏菜单栏
//添加按钮到自定义工具栏
//poCtrl1.addCustomToolButton("另存为", "Show1()", 1);
poCtrl1.addCustomToolButton("全屏/还原", "IsFullScreen", 4);
//poCtrl1.addCustomToolButton("刷新", "flash", 5);
poCtrl1.addCustomToolButton("打印", "Print()", 6);
//设置保存页面
//设置 PageOfficeCtrl 控件的数据对象
poCtrl1.setWriter(doc);
poCtrl1.webOpen(filepath+"/modelpath/"+fileName,OpenModeType.docReadOnly, "租金支付通知书");
//设置 PageOfficeCtrl 控件是否显示Office工具栏。
poCtrl1.setOfficeToolbars(false);
//此方法非常重要,在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();">
</body>
</html>