onlyoffice二次开发 支持API直接操作Word/Excel 明文源码 可读可进行二次开发
  eshgRBonckP8 2023年11月02日 101 0

本次改造基于V7.1.1+V7.3.3进行,已经更新进入docker。

小伙伴们须知:这部分内容需要付费

欢迎大家一起交流:V:cao_rui_jian_xiong

项目核心sdk_all.js等全部改造为明文,可以方便阅读和二次开发

下面是改造后的代码截取。

(function (window) {
    var MAX_ACTION_TIME = 20;
    var TIMEOUT_TIME = 20;
    function CActionOnTimerBase() {
      this.TimerId = null;
      this.Start = false;
      this.FirstActionOnTimer = false;
    }
    CActionOnTimerBase.prototype.Begin = function () {
      if (this.Start) this.End();
      this.Start = true;
      this.OnBegin.apply(this, arguments);
      var oThis = this;
      if (this.FirstActionOnTimer)
        this.TimerId = setTimeout(function () {
          oThis.Continue();
        }, TIMEOUT_TIME);
      else this.Continue();
    };
    CActionOnTimerBase.prototype.Continue = function () {
      if (this.IsContinue()) {
        var nTime = performance.now();
        this.OnStartTimer();
        while (this.IsContinue()) {
          if (performance.now() - nTime > MAX_ACTION_TIME) break;
          this.DoAction();
        }
        this.OnEndTimer();
      }
      var oThis = this;
      if (this.IsContinue())
        this.TimerId = setTimeout(function () {
          oThis.Continue();
        }, TIMEOUT_TIME);
      else this.End();
    };
    CActionOnTimerBase.prototype.End = function () {
      this.Reset();
      if (this.Start) {
        this.Start = false;
        this.OnEnd();
      }
    };
    CActionOnTimerBase.prototype.Reset = function () {
      if (this.TimerId) clearTimeout(this.TimerId);
      this.TimerId = null;
      this.Index = -1;
    };
    CActionOnTimerBase.prototype.SetDoFirstActionOnTimer = function (
      isOnTimer
    ) {
      this.FirstActionOnTimer = isOnTimer;
    };
    CActionOnTimerBase.prototype.OnBegin = function () {};
    CActionOnTimerBase.prototype.OnEnd = function () {};
    CActionOnTimerBase.prototype.IsContinue = function () {
      return false;
    };
    CActionOnTimerBase.prototype.OnStartTimer = function () {};
    CActionOnTimerBase.prototype.DoAction = function () {};
    CActionOnTimerBase.prototype.OnEndTimer = function () {};
    window["AscCommon"] = window["AscCommon"] || {};
    window["AscCommon"].CActionOnTimerBase = CActionOnTimerBase;
  })(window);
  ("use strict");
  (function (window) {
    var g_oCanvas = null;
    var g_oTable = null;
    function GetCanvas() {
      if (g_oCanvas == null) {
        g_oCanvas = document.createElement("canvas");
        g_oCanvas.width =
          (TABLE_STYLE_WIDTH_PIX * AscCommon.AscBrowser.retinaPixelRatio) >> 0;
        g_oCanvas.height =
          (TABLE_STYLE_HEIGHT_PIX * AscCommon.AscBrowser.retinaPixelRatio) >> 0;
      }
      return g_oCanvas;
    }
    function GetTable(oLogicDocument) {
      if (g_oTable == null) g_oTable = oLogicDocument.GetTableForPreview();
      oLogicDocument.CheckTableForPreview(g_oTable);
      return g_oTable;
    }
    function CTableStylesPreviewGenerator(oLogicDocument) {
      AscCommon.CActionOnTimerBase.call(this);
      this.FirstActionOnTimer = true;
      this.Api = oLogicDocument.GetApi();
      this.LogicDocument = oLogicDocument;
      this.DrawingDocument = oLogicDocument.GetDrawingDocument();
      this.TableStyles = [];
      this.TableLook = null;
      this.Index = -1;
      this.Buffer = [];
    }
    CTableStylesPreviewGenerator.prototype = Object.create(
      AscCommon.CActionOnTimerBase.prototype
    );
    CTableStylesPreviewGenerator.prototype.constructor =
      CTableStylesPreviewGenerator;
    CTableStylesPreviewGenerator.prototype.OnBegin = function (
      isDefaultTableLook
    ) {
      this.TableStyles = this.LogicDocument.GetAllTableStyles();
      this.Index = -1;
      this.TableLook = this.DrawingDocument.GetTableLook(isDefaultTableLook);
      this.Api.sendEvent(
        "asc_onBeginTableStylesPreview",
        this.TableStyles.length
      );
    };
    CTableStylesPreviewGenerator.prototype.OnEnd = function () {
      this.Api.sendEvent("asc_onEndTableStylesPreview");
    };
    CTableStylesPreviewGenerator.prototype.IsContinue = function () {
      return this.Index < this.TableStyles.length;
    };
    CTableStylesPreviewGenerator.prototype.DoAction = function () {
      var oPreview = this.GetPreview(this.TableStyles[this.Index]);
      if (oPreview) this.Buffer.push(oPreview);
      this.Index++;
    };
    CTableStylesPreviewGenerator.prototype.OnEndTimer = function () {
      this.Api.sendEvent("asc_onAddTableStylesPreview", this.Buffer);
      this.Buffer = [];
    };
    CTableStylesPreviewGenerator.prototype.GetAllPreviews = function (
      isDefaultTableLook
    ) {
      var oTableLookOld = this.TableLook;
      this.TableLook = this.DrawingDocument.GetTableLook(isDefaultTableLook);
      var arrStyles = this.LogicDocument.GetAllTableStyles();
      var arrPreviews = [];
      for (
        var nIndex = 0, nCount = arrStyles.length;
        nIndex < nCount;
        ++nIndex
      ) {
        var oPreview = this.GetPreview(arrStyles[nIndex]);
        if (oPreview) arrPreviews.push(oPreview);
      }
      this.TableLook = oTableLookOld;
      return arrPreviews;
    };
    CTableStylesPreviewGenerator.prototype.GetAllPreviewsNative = function (
      isDefaultTableLook,
      oGraphics,
      oStream,
      oNative,
      dW,
      dH,
      nW,
      nH
    ) {
      var oTableLookOld = this.TableLook;
      this.TableLook = this.DrawingDocument.GetTableLook(isDefaultTableLook);
      var arrStyles = this.LogicDocument.GetAllTableStyles();
      oNative["DD_PrepareNativeDraw"]();
      for (
        var nIndex = 0, nCount = arrStyles.length;
        nIndex < nCount;
        ++nIndex
      ) {
        var oStyle = arrStyles[nIndex];
        var oTable = this.GetTable(oStyle);
        oNative["DD_StartNativeDraw"](nW, nH, dW, dH);
        this.DrawTable(oGraphics, oTable);
        oStream["ClearNoAttack"]();
        oStream["WriteByte"](2);
        oStream["WriteString2"]("" + oStyle.GetId());
        oNative["DD_EndNativeDraw"](oStream);
        oGraphics.ClearParams();
      }
      oStream["ClearNoAttack"]();
      oStream["WriteByte"](3);
      oNative["DD_EndNativeDraw"](oStream);
      this.TableLook = oTableLookOld;
    };
    CTableStylesPreviewGenerator.prototype.GetPreview = function (oStyle) {
      if (!oStyle) return null;
      var _pageW = 297;
      var _pageH = 210;
      var _canvas = GetCanvas();
      var ctx = _canvas.getContext("2d");
      ctx.fillStyle = "#FFFFFF";
      ctx.fillRect(0, 0, _canvas.width, _canvas.height);
      var graphics = new AscCommon.CGraphics();
      graphics.init(ctx, _canvas.width, _canvas.height, _pageW, _pageH);
      graphics.m_oFontManager = AscCommon.g_fontManager;
      graphics.transform(1, 0, 0, 1, 0, 0);
      var oTable = this.GetTable(oStyle);
      this.DrawTable(graphics, oTable);
      var _styleD = new AscCommon.CStyleImage();
      _styleD.type = AscCommon.c_oAscStyleImage.Default;
      _styleD.image = _canvas.toDataURL("image/png");
      _styleD.name = oStyle.GetId();
      _styleD.displayName = oStyle.GetName();
      return _styleD;
    };
    CTableStylesPreviewGenerator.prototype.GetTable = function (oStyle) {
      var oTable = GetTable(this.LogicDocument);
      var oTableLook = this.TableLook;
      AscCommon.ExecuteNoHistory(function () {
        oTable.Set_Props({
          TableStyle: oStyle.GetId(),
          TableLook: oTableLook,
          CellSelect: false,
        });
        oTable.Recalc_CompiledPr2();
      }, this.LogicDocument);
      return oTable;
    };
    CTableStylesPreviewGenerator.prototype.DrawTable = function (
      oGraphics,
      oTable
    ) {
      oTable.Recalculate_Page(0);
      var _old_mode = editor.isViewMode;
      editor.isViewMode = true;
      editor.isShowTableEmptyLineAttack = this.LogicDocument.IsDocumentEditor();
      oTable.Draw(0, oGraphics, false);
      editor.isShowTableEmptyLineAttack = false;
      editor.isViewMode = _old_mode;
    };
    window["AscCommon"] = window["AscCommon"] || {};
    window["AscCommon"].CTableStylesPreviewGenerator =
      CTableStylesPreviewGenerator;
  })(window);
  ("use strict");
  (function (window, undefined) {
    function FileHandler() {
      this.get = function (file) {
        if (AscCommon.AscBrowser.isAppleDevices) {
          var downloadWindow = window.open(file, "_parent", "", false);
          window.focus();
        } else var frmWindow = getIFrameWindow(file);
      };
      var getIFrameWindow = function (file) {
        var ifr = document.getElementById("fileFrame");
        if (null != ifr) document.body.removeChild(ifr);
        createFrame(file);
        var wnd = window.frames["fileFrame"];
        return wnd;
      };
      var createFrame = function (file) {
        var frame = document.createElement("iframe");
        frame.src = file;
        frame.name = "fileFrame";
        frame.id = "fileFrame";
        frame.style.width = "0px";
        frame.style.height = "0px";
        frame.style.border = "0px";
        frame.style.display = "none";
        document.body.appendChild(frame);
      };
    }
    function getFile(filePath) {
      var fh = new FileHandler();
      fh.get(filePath);

解析前的代码还是很难读懂的。

onlyoffice二次开发 支持API直接操作Word/Excel 明文源码 可读可进行二次开发_二次开发

明文解析后,增加了原生API的调用

onlyoffice二次开发 支持API直接操作Word/Excel 明文源码 可读可进行二次开发_二次开发_02


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
eshgRBonckP8