您的位置:首页 > 其它

点聚weboffice插件自定义菜单

2016-12-22 19:05 183 查看

1、在jsp中引用excel插件:

首先项目中要有:WebOffice.zip、weboffice_Set.exe这是点聚weboffice的插件

<object id=WebOffice height=400 width='100%' style='LEFT: 0px; TOP: 0px;padding-bottom: 0px;margin-bottom: 0px;'
classid='clsid:E77E049B-23FC-4DB8-B756-60529A35FAD5' codebase='<%=request.getContextPath()%>/tool/ExcelTool/WebOffice.cab'>
<param name='_ExtentX' value='6350'>
<param name='_ExtentY' value='6350'>
</object>
定义一个插件对象

2、添加自定义菜单

<script type="text/javascript">
var showmenu=0;
var showfull=0;
function WebOffice1_NotifyToolBarClick(iIndex){
//添加自定义按钮
webObj.SetCustomToolBtn(0,"打开文档");
//webObj.SetCustomToolBtn(1,"保存文档");
webObj.SetCustomToolBtn(2,"显示菜单");
webObj.SetCustomToolBtn(3,"全屏显示");

if(iIndex==32776){
try{console.log("打开文档");}catch(e){};
try{webObj.LoadOriginalFile("open", "xls");}catch(e){};
}else if(iIndex==32777){
try{console.log("保存文档");}catch(e){};
/*  try{webObj.Save();
}catch(e){
alert("异常\r\nError:"+e+"\r\nError Code:"+e.number+"\r\nError Des:"+e.description);
}  */
try{webObj.ShowDialog(145);}catch(e){}
}else if(iIndex==32778){
if(showmenu==0){
try{console.log("显示菜单");}catch(e){};
try{webObj.SetCustomToolBtn(2,"隐藏菜单");}catch(e){};
try{webObj.SetToolBarButton2("Menu Bar",1,11);}catch(e){};//03
try{webObj.HideMenuArea('showmenu','','','');}catch(e){};//07
showmenu=1;
}else{
try{console.log("隐藏菜单");}catch(e){};
try{webObj.SetCustomToolBtn(2,"显示菜单");}catch(e){};
try{webObj.SetToolBarButton2("Menu Bar",1,8);}catch(e){};//03
try{webObj.HideMenuArea('hideall','','','');}catch(e){};//07
showmenu=0;
}
}else if(iIndex==32779){
if(showfull==0){
try{console.log("全屏显示");}catch(e){};
try{webObj.SetCustomToolBtn(3,"退出全屏");}catch(e){};
try{webObj.FullScreen = true;}catch(e){};
showfull=1;
}else{
try{console.log("退出全屏");}catch(e){};
try{webObj.SetCustomToolBtn(3,"全屏显示");}catch(e){};
try{webObj.FullScreen = false;}catch(e){};
showfull=0;
}
}
}
//生成Excel
        //createExcel("WebOffice");
        //设置Excel属性
        var webObj =null;
        var SpreadExcel = null;
        var fristname="";
        function onloadexcel() {
            document.body.removeChild(document.getElementById("loading"));
            webObj = document.getElementById("WebOffice");
            webObj.height=document.body.scrollHeight-35;
            //设置默认打开word或者excel
            webObj.LoadOriginalFile("", "xls");
    /*         //隐藏"新建文档"
            webObj.HideMenuItem(0x01);
            //隐藏"打印文档"
            webObj.HideMenuItem(0x10);
            //隐藏"打印预览"
            webObj.HideMenuItem(0x20);
            //设置菜单栏为隐藏状态
            webObj.HideMenuArea('hideall', '', '', ''); */
            
            
          webObj.HideMenuItem(0x01);
          webObj.HideMenuItem(0x02);
          webObj.HideMenuItem(0x04);
          webObj.HideMenuItem(0x10);
          webObj.HideMenuItem(0x20);
          webObj.HideMenuItem(0x4000);
          webObj.HideMenuItem(0x1000);
          webObj.HideMenuArea('hideall','','','');
            
             /*定义按钮(插件只提供了5个按钮)*/
            //添加自定义按钮
            webObj.SetCustomToolBtn(0,"打开文档");
            webObj.SetCustomToolBtn(1,"保存文档");
            webObj.SetCustomToolBtn(2,"显示菜单");
            webObj.SetCustomToolBtn(3,"全屏显示");
            
           //得到office文档对象;
            SpreadExcel = webObj.GetDocumentObject();
</script>


最后在<head>中调用

<script language=javascript event=NotifyToolBarClick(iIndex) for=WebOffice>
WebOffice1_NotifyToolBarClick(iIndex);
</script>


3、说明:

这个插件自带的菜单已经可以满足很多需求了,只是我们需要把原先自带的简体改为繁体,所以用到自定义菜单功能。

需要说明的是,点聚中的main.js中的接口,另存为是:webObj.ShowDialog(84),但是我使用后显示的效果却似“设置单元格”,被人告诉我说84是常量值,然后我就从84开始试,到145出现另存为的功能。我本地安装的是2010完全版的office,目前测试了2007的office,其他版本的效果不清楚。

4、效果

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息