1. 程式人生 > >點聚weboffice外掛自定義選單

點聚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
版權宣告:本文為博主原創文章,轉載請附上博文連結!

效果