pageoffice在线编辑word文件并禁止选中

发布时间 2023-05-06 14:01:36作者: qianxi

一、整篇文档禁止选中

image

wordDoc.setDisableWindowSelection(true); //禁止word的选择文字功能

二、根据条件判断是否禁止选中

比如:选中内容超过一定字数,取消选中

解决方案:使用后端提供的OnWordSelectionChange事件。

PageOfficeCtrl poCtrl = new PageOfficeCtrl(request);
poCtrl.setServerPage(request.getContextPath() + "/poserver.zz");
poCtrl.setJsFunction_OnWordSelectionChange("OnWordSelectionChange()");
function OnWordSelectionChange() {
        var obj = document.getElementById("PageOfficeCtrl1").Document.Application.Selection;
        if (obj.Range.Text != "") {
            if (obj.Range.Text.length>7) {
                alert("最多可以选中7个,您选中"+obj.Range.Text.length+"个文字,请重新选择");
                //取消选中
                document.getElementById("PageOfficeCtrl1").Document.Application.Selection.Move();
            }else{
                alert("选中内容:"+obj.Range.Text);
            }
        }
    }

image

image

转载:https://blog.csdn.net/wqqqianqian/article/details/127921452?spm=1001.2014.3001.5502