iweboffice2004 是一个实现痕迹保留、手写签名、电子印章的插件,已经被100多个
单位使用,将其调用部分office vba代码整理如下:
<script language=javascript>
//系统变量
var vfilename=""; //打开的文件名
var vobject=null; //打开的对象
var gfilename=""; //文件名
var gobject=null; //对象
var gopened=false; //是否被打开
var gusername=""; //系统用户
</script>
<script language="jscript" for=weboffice event="ondocumentopened(vfilename,vobject)">
ondocumentopened(vfilename,vobject); //打开文件事件
</script>
<script language="jscript" for=weboffice event="ondocumentclosed()">
ondocumentclosed(); //关闭文件事件
</script>
<script language=javascript>
//打开文档,根据用户权限(edittype),进行初始化设置
function ondocumentopened(vfilename,vobject)
{
var mprotect,mtools,mtrack,mprint,mshow;
gfilename=vfilename; //取得全局文件名
gobject=vobject; //取得全局对象
//设置痕迹和保护状态
if (webform.weboffice.edittype=="0"){
mprotect=true;
mtools=false;
mtrack=false;
mprint=false;
mshow=true;
}else if(webform.weboffice.edittype=="1"){
mprotect=false;
mtools=false;
mtrack=false;
mprint=false;
mshow=false;
}else if(webform.weboffice.edittype=="2"){
mprotect=false;
mtools=false;
mtrack=true;
mprint=true;
mshow=true;
}else if(webform.weboffice.edittype=="3"){
mprotect=false;
mtools=true;
mtrack=true;
mprint=true;
mshow=true;
}else{
var mtype="";
var medit=webform.weboffice.edittype;
var midx=medit.indexof(",");
if (midx>0){
mtype=medit.substring(0,midx);
}
medit=medit.substring(midx+1,medit.length);
midx=medit.indexof(",");
if (midx>0){
mtype=medit.substring(0,midx);
if (mtype=="1") mprotect=true;
if (mtype=="0") mprotect=false;
}
medit=medit.substring(midx+1,medit.length);
var midx=medit.indexof(",");
if (midx>0){
mtype=medit.substring(0,midx);
if (mtype=="1") mshow=true;
if (mtype=="0") mshow=false;
}
medit=medit.substring(midx+1,medit.length);
var midx=medit.indexof(",");
if (midx>0){
mtype=medit.substring(0,midx);
if (mtype=="1") mtrack=true;
if (mtype=="0") mtrack=false;
}
medit=medit.substring(midx+1,medit.length);
var midx=medit.indexof(",");
if (midx>0){
mtype=medit.substring(0,midx);
if (mtype=="1") mprint=true;
if (mtype=="0") mprint=false;
}
medit=medit.substring(midx+1,medit.length);
var midx=medit.indexof(",");
if (midx>0){
mtype=medit.substring(0,midx);
if (mtype=="1") mtools=true;
if (mtype=="0") mtools=false;
}
}
if (webform.weboffice.filetype==".doc"){
gobject.trackrevisions=mtrack;
gobject.printrevisions=mprint;
gobject.showrevisions=mshow;
gobject.commandbars('reviewing').enabled =mtools;
gobject.commandbars('reviewing').visible =mtools;
var mcount=gobject.commandbars('track changes').controls.count;
for (var mindex = 1; mindex<= mcount; mindex++){
var mcurid=gobject.commandbars('track changes').controls(mindex).id;
if ((mcurid==1715) || (mcurid==1716) || (mcurid==2041) || (mcurid==305)) {
gobject.commandbars('track changes').controls(mindex).enabled = mtools;
}
}
if (mprotect){
gobject.protect(2);
}
if (gusername == "") {
//保存原来的用户
gusername=gobject.application.username;