iWebOffice2004 是一个实现痕迹保留、手写签名、电子印章的插件,已经被100多个
单位使用,将其调用部分Office VBA代码整理如下:
来自 http://www.goldgrid.com
<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;
//设置系统当前用户
gObject.Application.UserName=webform.WebOffice.UserName;
}
}
if (webform.WebOffice.FileType==".xls"){
if (mShow){
if (mTrack){
gObject.Application.DisplayCommentIndicator = 1;
}
}else{
gObject.Application.DisplayCommentIndicator = 0;
}
gObject.CommandBars('Reviewing').Enabled =mTools;
gObject.CommandBars('Reviewing').Visible =mTools;
if (mProtect){
for (var mIndex=1;mIndex<=gObject.Application.ActiveWorkbook.Sheets.Count;mIndex++){
var mSheet=gObject.Application.ActiveWorkbook.Sheets(mIndex);
mSheet.Protect("", true, true, true);
}
}
if (gUserName == "") {
//保存原来的用户
gUserName=gObject.Application.UserName;
//设置系统当前用户
gObject.Application.UserName=webform.WebOffice.UserName;
}
}
//打开成功
gOpened = true;
}
function OnDocumentClosed()
{
//关闭成功
gOpened = false;
}
//显示系统状态信息
function StatusMsg(mString){
StatusBar.innerText=mString;
}
//页面装入事件
function Load(){
//给控件属性付值
try{
webform.WebOffice.WebUrl="<%=mServerUrl%>";
webform.WebOffice.RecordID="<%=mRecordID%>";
webform.WebOffice.Template="<%=mTemplate%>";
webform.WebOffice.FileName="<%=mFileName%>";
webform.WebOffice.FileType="<%=mFileType%>";
webform.WebOffice.EditType="<%=mEditType%>";
webform.WebOffice.UserName="<%=mUserName%>";
//打开文档,执行发送LOADFILE操作
webform.WebOffice.WebOpen();
if (webform.WebOffice.Error!=""){
//如果不成功,执行发送LOADTEMPLATE操作
webform.WebOffice.WebLoadTemplate();
if (webform.WebOffice.Error!=""){
//如果还没有成功,则根据扩展名创建新文档
if (webform.WebOffice.FileType==".doc"){
webform.WebOffice.CreateNew("Word.Document");
}else if(webform.WebOffice.FileType==".xls"){
webform.WebOffice.CreateNew("Excel.Sheet");
}else if(webform.WebOffice.FileType==".ppt"){
webform.WebOffice.CreateNew("PowerPoint.Show");
}else{
webform.WebOffice.CreateNew("");
}
}
}
}catch(e){
}
//显示状态信息
StatusMsg(webform.WebOffice.Status);
}
//页面退出事件
function UnLoad(){
try{
//关闭OCX控件
webform.WebOffice.WebClose();
}catch(e){}
}
//设置是否显示痕迹
function ShowRevision(vValue){
var object=webform.WebOffice.ActiveDocument;
object.ShowRevisions=vValue;
if (vValue){
StatusMsg("显示痕迹...");
}else{
StatusMsg("隐藏痕迹...");
}
}
//调入文档
function LoadDocument(){
StatusMsg("正在打开文档...");
webform.WebOffice.WebOpen();
StatusMsg(webform.WebOffice.Status);
}
//保存文档
function SaveDocument(){
//判断状态
if (webform.EditType.value=="0"){
alert("你在查看状态,不能保存!");
return false;
}
//保存文档
webform.WebOffice.WebSave();
//如果没有错误
if (webform.WebOffice.Error!=""){
StatusMsg(webform.WebOffice.Status);
return false;
}else{
StatusMsg(webform.WebOffice.Status);
return true;
}
}
//打开版本信息
function WebOpenVersion(){
var mDialogUrl = "Version/VersionList.asp?RecordID="+webform.WebOffice.RecordID;
var mObject = new Object();
mObject.FileID = "";
mObject.Result = false;
window.showModalDialog(mDialogUrl, mObject, "dialogHeight:280px; dialogWidth:420px;c