pageoffice实现预览和打印

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>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值