初始化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){};
}