vue項目集成金格WebOffice2015


下載

官網地址:http://www.goldgrid.com/jinge_download/index.aspx?num=5
在這里插入圖片描述

  • 解壓后的文件
    在這里插入圖片描述
  • js文件中有兩個重要的js文件iWebOffice2015.jsWebOffice.js
  • WebOffice.js是WebOffice2015對象的一些方法。
  • iWebOffice2015.js是根據不同的瀏覽器環境來渲染<object>
    在這里插入圖片描述

實現

iWebOffice2015.jsWebOffice.js放入static目錄下

在這里插入圖片描述

index.html中引入WebOffice.js

在這里插入圖片描述

修改iWebOffice2015.js

  • 官網iWebOffice2015.js源文件在下面截圖處少了一個閉合標簽,如下圖添加
    在這里插入圖片描述

  • 由於異步加載不允許使用document.write方法,這里注釋掉document.write(str)
    在這里插入圖片描述

  • 【可選操作】,注釋瀏覽器判斷,這里由於未寫入文檔流,所以獲取一些屬性是出錯的,如document.getElementById("WebOffice").type,注釋掉就可以

/*注釋以下代碼*/
/*if ((window.ActiveXObject != undefined) || (window.ActiveXObject != null) || "ActiveXObject" in window) {

} else {
	if (browser == "firefox") {
		if(version < "52"){
			var fireFoxType = navigator.mimeTypes["application/kg-activex"];
			if (fireFoxType == undefined) {
				document.getElementById("WebOffice").width = "1px";
				var str='<div width="100%" height="100%" style="text-align:center; color: red;font-size:30px;" >該插件不受支持</br>點擊跳轉解決方案</div>';
				var t = document.getElementById("OfficeDiv");
				t.innerHTML = t.innerText + str;
			}
		}else{
			document.getElementById("WebOffice").width = "1px";
			var str='<div width="100%" height="100%" style="text-align:center;color: red;font-size:30px;" >該插件不受支持</br>請更換52版本以下的FireFox瀏覽器</div>';
			var t = document.getElementById("OfficeDiv");
			t.innerHTML = t.innerText + str;
		}
	}else if(browser == "chrome"){
		 var kgchromeType = navigator.mimeTypes["application/kg-plugin"]; //高級版
		 var chromeType = navigator.mimeTypes["application/kg-activex"]; //標准版
		 var oldChromeType = navigator.mimeTypes["application/iWebPlugin"]; //早期淘汰版本
		 if(document.getElementById("WebOffice").type == "application/kg-plugin"){
			 if (kgchromeType == undefined) {
				 document.getElementById("WebOffice").width = "1px";
				 var str='<div width="100%" height="100%" style="text-align:center; color: red;font-size:30px;" >該插件不受支持</br>引用的是高級版控件</br></div>';
				 var t = document.getElementById("OfficeDiv");
				 t.innerHTML = t.innerText + str;
				 //window.open("Faq002.html");
			 }	
		 }else{
			 if(version > "45"){
				 if (chromeType == undefined || oldChromeType == undefined) {
					 document.getElementById("WebOffice").width = "1px";
					 var str='<div width="100%" height="100%" style="text-align:center;color: red;font-size:30px;" >該插件不受支持</br>引用的是標准版控件</br></div>';
					 var t = document.getElementById("OfficeDiv");
					 t.innerHTML = t.innerText + str;
				 }	
			 }else{
				 document.getElementById("WebOffice").width = "1px";
				 var str='<div width="100%" height="100%" style="text-align:center;color: red;font-size:30px;" >標准版插件不受支持</br>請更換45版本以下的Chrome瀏覽器</br>如果需要使用高版本Chrome瀏覽器,需集成高級版插件</div>';
				 var t = document.getElementById("OfficeDiv");
				 t.innerHTML = t.innerText + str;
			 }
		 }
	}
}
*/
  • iWebOffice2015.js末尾將拼接好的字符串暴露出來
    在這里插入圖片描述

    代碼示例

    • vue文件中import引入iWebOffice2015.js
    • initWebOffice通過創建vue實例手動掛載來渲染<object>,將剛才暴露出來的<object>加載到office
    • initWebOfficeObject中的關鍵點是this.webOfficeObj.CreateFile() ,創建一個空白的文檔
    <template>
      <div style="width:100%;height:100%;">
        <div id="office"></div>
      </div>
    </template>
    <script>
      import Vue from 'vue';
      import webOfficeTpl from '../../../../../static/webOffice/iWebOffice2015.js';
      export default {
        data() {
          return {
            webOffice: null,
            webOfficeObj: null
          }
        },
        beforeCreate(){
    
        },
        mounted(){
          console.log(webOfficeTpl);
          this.$nextTick(() => {
            this.initWebOffice();
            this.initWebOfficeObject();
          })
        },
        beforeDestroy() {
    
        },
        methods: {
          initWebOffice() {
            this.webOffice = new Vue({
              template: webOfficeTpl
            }).$mount('#office');
          },
          initWebOfficeObject() {
            this.webOfficeObj = new WebOffice2015();
            this.webOfficeObj.setObj(document.getElementById('WebOffice'));
            try{
              //this.webOfficeObj.ServerUrl = "http://www.kinggrid.com:8080/iWebOffice2015/OfficeServer";
              //this.webOfficeObj.RecordID = "1551950618511";  //RecordID:本文檔記錄編號
              this.webOfficeObj.UserName = "XXX";
              this.webOfficeObj.FileName = "Mytemplate.doc";
              this.webOfficeObj.FileType = ".doc"; //FileType:文檔類型  .doc  .xls
              this.webOfficeObj.ShowWindow = false; //顯示/隱藏進度條
              this.webOfficeObj.EditType = "1"; //設置加載文檔類型 0 鎖定文檔,1無痕跡模式,2帶痕跡模式
              this.webOfficeObj.ShowMenu = 1;
              this.webOfficeObj.ShowToolBar = 0;
              this.webOfficeObj.SetCaption(this.webOfficeObj.UserName + "正在編輯文檔"); // 設置控件標題欄標題文本信息
              //參數順序依次為:控件標題欄顏色、自定義菜單開始顏色、自定義工具欄按鈕開始顏色、自定義工具欄按鈕結束顏色、
              //自定義工具欄按鈕邊框顏色、自定義工具欄開始顏色、控件標題欄文本顏色(默認值為:0x000000)
              if (!this.webOfficeObj.WebSetSkin(0xdbdbdb, 0xeaeaea, 0xeaeaea, 0xdbdbdb, 0xdbdbdb, 0xdbdbdb, 0x000000)) {
                alert(this.webOfficeObj.Status);
              }    //設置控件皮膚
              if(this.webOfficeObj.WebOpen()) {
                // StatusMsg(WebOfficeObj.Status);
              }
              this.webOfficeObj.AppendMenu("1","打開本地文件(&L)");
              this.webOfficeObj.AppendMenu("2","保存本地文件(&S)");
              this.webOfficeObj.AppendMenu("3","-");
              this.webOfficeObj.AppendMenu("4","打印預覽(&C)");
              this.webOfficeObj.AppendMenu("5","退出打印預覽(&E)");
              this.webOfficeObj.AddCustomMenu();
              this.webOfficeObj.HookEnabled();
              this.webOfficeObj.CreateFile() // 根據FileType設置的擴展名來創建對應的空白文檔
            }
            catch(e){
              console.log("catch");
              console.log(e.description);
            }
          }
    
        }
      }
    </script>
    <style lang="less">
    
    </style>
    

    效果

    在這里插入圖片描述


    參考文章:vue項目如何集成金格WebOffice2015,集成的過程中借鑒了該篇博客中的實現思路,遇到問題的童鞋可參考這篇博客

    注:遇到錯誤可參考

    • 如瀏覽器打開提示不支持插件,先核實是否安裝了iWebOfiice2015.msi,如已安裝,打開這里的企業應用瀏覽器進行測試
      在這里插入圖片描述
    • 啟動KGPMSYS服務
      在這里插入圖片描述
    posted @ 2019-08-27 10:43  95.8℃  閱讀( 1403)  評論( 1編輯  收藏


免責聲明!

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



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