pageoffice自动显示所有批注

pageoffice有api可以直接调用, 显示所有批注,但目前只支持word.对于excel.可以使用编写宏,直接调用office的功能.直接上代码

//POB打开窗口后事件
function AfterDocumentOpened() {
    document.getElementById("PageOfficeCtrl1").ShowRevisions = true;//word显示批注
    if(fileType && "excel" == fileType){
       showComments();
    }
}

/**
* excel显示所有批注
* pageoffice目前没有可以直接调用的接口.这里使用宏调用office的功能
*/
function showComments(){
   var mac = "Sub showComments()" + " \r\n"
               + "Dim count As Integer" + " \r\n"
               + "count = ActiveSheet.Comments.count" + " \r\n"
               + "If count > 0 Then" + " \r\n"
               +  "    Dim cmt As Comment" + " \r\n"
               +  "     For Each cmt In ActiveSheet.Comments" + " \r\n"
               +  "         cmt.Visible = True" + " \r\n"
               +  "     Next cmt" + " \r\n"
               + "End If" + " \r\n"
               +  "End Sub" + " \r\n";
               document.getElementById("PageOfficeCtrl1").RunMacro("showComments", mac);
}

另外要注意的是,由于这里是应用写宏脚本调用office.故要调整office的信任设置:如下

设置信任

发布了53 篇原创文章 · 获赞 5 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_40085888/article/details/101695817
今日推荐