GGrid office 和 NTKO office相互替换的封装实现方法

初始化office:

 //GGrid
//document.all("bottonFrame").src="${ctx}/template/template!openLocalFile.action?deptId=${deptId}&typeId=${typeId}&templateModel.tempId=${tempId}";

         //NTKO
         $("#btFrame").height($(window).height());
document.all("bottonFrame").src="${ctx}/weboffice/officepage.jsp?fileType=word";


保存office:

/*GGrid
window.frames["bottonFrame"].webform.WebOffice.WebShow(false);
window.frames["bottonFrame"].saveDoc();
var fName = window.frames["bottonFrame"].webform.WebOffice.FileName;
*/

//NTKO
var tp='${tempPath}',fName='';
if(tp==null||tp==''){
<%String newfilename=System.currentTimeMillis()+"";%>
      document.getElementById('btFrame').contentWindow.SaveOffice('<%=newfilename%>','');
fName='<%=newfilename%>'+'.doc';
}else{
document.getElementById('btFrame').contentWindow.SaveOffice(tp.replace('.doc',''),'');
fName=tp;
}


返回所有书签:

//GGrid

//var tags=window.frames['bottonFrame'].getBookMarkNameValue();

//NTKO
var tags=document.getElementById('btFrame').contentWindow.getBookMark();


得到书签:

//GGrid

//window.frames["bottonFrame"].GetBookmarksName();//获得word中所有标签的名称串 aaa,bbb

//NTKO
document.getElementById('btFrame').contentWindow.getBookMarkNameValue();


删除书签:

//window.frames["bottonFrame"].delMarks(bookname);
document.getElementById('btFrame').contentWindow.delMarks(bookname);


定位书签:

//window.frames["bottonFrame"].gotoMarks(bookname);
document.getElementById('btFrame').contentWindow.gotoMarks(bookname);


对应的封装实现方法如下:

function getBookMark(){//获取所有书签 return:数组
try{
var myarray = new Array();
for(i=0;i<OFFICE_CONTROL_OBJ.ActiveDocument.Bookmarks.Count;i++){
myarray[i] = new Array(OFFICE_CONTROL_OBJ.ActiveDocument.Bookmarks.Item(i+1).Name,OFFICE_CONTROL_OBJ.GetBookmarkValue(OFFICE_CONTROL_OBJ.ActiveDocument.Bookmarks.Item(i+1).Name));
}
return myarray;
   }catch(err){};
}
function addBookMarks(bookname,bookvalue){//添加书签
try{
OFFICE_CONTROL_OBJ.ActiveDocument.Bookmarks.Add(bookname,OFFICE_CONTROL_OBJ.ActiveDocument.Application.Selection.Range);
OFFICE_CONTROL_OBJ.SetBookmarkValue(bookname,bookvalue);
   }catch(err){};
}
function getBookMarkNameValue(){///获取书签名 逗号分隔 return:字符串 逗号分隔
    var _ret="";
try{
var myarray = new Array();
                   
for(i=0;i<OFFICE_CONTROL_OBJ.ActiveDocument.Bookmarks.Count;i++){
  _ret+=OFFICE_CONTROL_OBJ.ActiveDocument.Bookmarks.Item(i+1).Name+",";
}
  }catch(err){};
if(_ret.length>0)
  _ret=_ret.substring(0,_ret.length-1);
return _ret;
}

function delMarks(bookname){//删除书签
try{
OFFICE_CONTROL_OBJ.SetBookmarkValue(bookname,"");
OFFICE_CONTROL_OBJ.ActiveDocument.Bookmarks(bookname).Delete();
   }catch(err){};
}
function gotoMarks(bookname){//定位书签
    try{
OFFICE_CONTROL_OBJ.ActiveDocument.Application.Selection.GoTo(true,0,0,bookname);
   }catch(err){};
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值