點聚weboffice插件自定義菜單


https://blog.csdn.net/u014547764/article/details/53818637

 

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>

---------------------
作者:春夏秋冬---studio
來源:CSDN
原文:https://blog.csdn.net/u014547764/article/details/53818637
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!

 

 

3、說明:
這個插件自帶的菜單已經可以滿足很多需求了,只是我們需要把原先自帶的簡體改為繁體,所以用到自定義菜單功能。

需要說明的是,點聚中的main.js中的接口,另存為是:webObj.ShowDialog(84),但是我使用后顯示的效果卻似“設置單元格”,被人告訴我說84是常量值,然后我就從84開始試,到145出現另存為的功能。我本地安裝的是2010完全版的office,目前測試了2007的office,其他版本的效果不清楚。
---------------------
作者:春夏秋冬---studio
來源:CSDN
原文:https://blog.csdn.net/u014547764/article/details/53818637
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!

效果

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM