随笔 - 106  文章 - 0  评论 - 2  阅读 - 91570

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

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

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

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

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

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

2、实现过程

以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 打开之后,文档的正文不能改变,只能对文档进行加批注的操作效果。

原文链接:https://www.cnblogs.com/qingxue636/p/17048510.html

posted on   qianxi  阅读(344)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示