用pageOffice控件实现 office 文档在线编辑Word 只能加批注的功能

OA办公中,业务需要编辑打开word文档后 文档的正文不能改变,只能对文档进行加批注的操作

怎么实现编辑打开word文档后 文档的正文不能改变,只能对文档进行加批注的操作呢?

2 实现方法

通过pageOffice实现简单的在线打开编辑word时,
通过设置
关键代码:
WebOpen方法的第二个参数使用docCommentOnly,第三个参数传用户名,在Word文件只读的情况下向Word文件中插入键盘批注。

//打开Word文档
poCtrl.webOpen("/doc/CommentOnly/test.doc", OpenModeType.docCommentOnly, "张三");

就可以实现编辑打开word文档后 文档的正文不能改变,只能对文档进行加批注的操作。

3 实现过程

以java的springboot框架为例

1 集成pageOffice

https://www.zhuozhengsoft.com/dowm/

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

2 在线打开编辑word

image

可以按照这个示例首先实现最基本的打开word的方法。

3 通过代码打开word文档后 文档的正文不能改变,只能对文档进行加批注的操作

示例参考

image

java代码

点击查看代码
@RestController
@RequestMapping(value = "/CommentOnly/")
public class CommentOnlyController {

    //获取doc目录的磁盘路径
    private String dir = GetDirPathUtil.getDirPath() + "static/doc/";

    @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");//设置服务页面
        //添加自定义按钮
        poCtrl.addCustomToolButton("保存", "Save", 1);
        poCtrl.addCustomToolButton("插入批注", "newComment", 0);
        //设置保存页面
        poCtrl.setSaveFilePage("save");//设置处理文件保存的请求方法
        //打开Word文档
        poCtrl.webOpen("/doc/CommentOnly/test.doc", OpenModeType.docCommentOnly, "张三");
        map.put("pageoffice", poCtrl.getHtmlCode("PageOfficeCtrl1"));
        ModelAndView mv = new ModelAndView("CommentOnly/Word");
        return mv;
    }

    @RequestMapping("save")
    public void save(HttpServletRequest request, HttpServletResponse response) {
        FileSaver fs = new FileSaver(request, response);
        fs.saveToFile(dir + "CommentOnly/" + fs.getFileName());
        fs.close();
    }
}

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>
    <meta charset="utf-8">
    <title>CommentOnly</title>
</head>
<body style="overflow:hidden">

<script type="text/javascript">
    function Save() {
        document.getElementById("PageOfficeCtrl1").WebSave();
    }

    function newComment() {
        var docSel = document.getElementById("PageOfficeCtrl1").Document.Application.Selection;
        docSel.Comments.Add(docSel.Range);
    }

</script>
</div>
<div style=" width:1100px; height:800px;" th:utext="${pageoffice}">
</div>
</body>
</html>

通过以上代码,可以实现 office 文档在线编辑Word 打开之后,文档的正文不能改变,只能对文档进行加批注的操作

4效果图

image

文档打开后,文档中的正文没有办法编辑,只能对文档中加批注。

5总结

用pageOffice控件实现 office 文档在线编辑Word 打开之后,文档的正文不能改变,只能对文档进行加批注的操作效果。

posted on 2023-01-13 09:02  Tony636  阅读(335)  评论(0编辑  收藏  举报