用pageOffice控件实现 office 文档在线编辑Word 打开文档后在页面里触发事件

OA办公中,业务需要编辑打开word文档后 执行一些js操作

怎么实现编辑打开word文档后 执行一些js操作呢?

2 实现方法

通过pageOffice实现简单的在线打开编辑word时,
通过设置
关键代码:
// 设置文件打开后执行的js function
poCtrl.setJsFunction_AfterDocumentOpened(“AfterDocumentOpened()”);

就可以实现编辑打开word文档后 执行一些js操作。

3 实现过程

以java的springboot框架为例

1 集成pageOffice

https://www.zhuozhengsoft.com/dowm/
在这里插入图片描述

从pageOffice官网
下载页面,找到springboot的集成示例,按照里面的集成明说,可以集成到自己的springboot项目中。

2 在线打开编辑word

在这里插入图片描述
可以按照这个示例首先实现最基本的打开word的方法。

3 通过代码打开word文档后 执行一些js操作

示例参考
在这里插入图片描述
java代码

点击查看代码

@RestController
@RequestMapping(value = "/AfterDocOpened")
public class AfterDocOpenedController {

    @RequestMapping(value = "/Word", method = RequestMethod.GET)
    public ModelAndView showWord(HttpServletRequest request, Map<String, Object> map) {
        PageOfficeCtrl poCtrl = new PageOfficeCtrl(request);
        poCtrl.setServerPage(request.getContextPath() + "/poserver.zz");//设置服务页面
        // 设置文件打开后执行的js function
        poCtrl.setJsFunction_AfterDocumentOpened("AfterDocumentOpened()");
        //打开Word文档
        poCtrl.webOpen("/doc/AfterDocOpened/test.doc", OpenModeType.docNormalEdit, "张三");
        map.put("pageoffice", poCtrl.getHtmlCode("PageOfficeCtrl1"));
        ModelAndView mv = new ModelAndView("AfterDocOpened/Word");
        return mv;
    }

}


html代码

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">

<head>
    <title>文件打开后触发的事件</title>

</head>
<body>
<script type="text/javascript">
    function AfterDocumentOpened() {
        // 打开文件的时候,给word中当前光标位置赋值一个文本值
        document.getElementById("PageOfficeCtrl1").Document.Application.Selection.Range.Text = "文件打开了";
    }

</script>
<form id="form1">
    Word中的"<span style=" color:Red;"> 文件打开了</span>" 是在文档打开的事件中用程序添加进去的。<br/><br/>

    <div style=" width:auto; height:700px;" th:utext="${pageoffice}">
    </div>
</form>
</body>

</html>


通过以上代码,可以实现 office 文档在线编辑Word 打开之后在页面里触发的事件

4 效果图

在这里插入图片描述
文档打开后,显示的 文件打开了 是通过AfterDocumentOpened的方法写到文档中的。

5 总结

用pageOffice控件实现 office 文档在线编辑Word 打开之后在页面里触发的事件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值