vue项目集成金格WebOffice2015

孤街浪徒 提交于 2019-11-28 17:39:24

下载

官网地址: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)
    在这里插入图片描述

  • 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>
  • 通过控制台可查看<object>
    在这里插入图片描述


效果

在这里插入图片描述
参考文章:vue项目如何集成金格WebOffice2015,集成的过程中借鉴了该篇博客中的实现思路,遇到问题的童鞋可参考这篇博客

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!