找回密码
 立即注册

QQ登录

只需一步,快速开始

chezhijun

金牌服务用户

4

主题

14

帖子

42

积分

金牌服务用户

积分
42
最新发帖
chezhijun
金牌服务用户   /  发表于:2021-8-20 09:36  /   查看:3604  /  回复:17
本帖最后由 Lynn.Dou 于 2021-8-27 11:59 编辑

spreadJS 14 有公式追溯功能嘛,等同于excel的ctrl+[ 或者 ctrl+]

17 个回复

正序浏览
Lynn.Dou讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2021-8-20 09:54:51
推荐
您好,
SpreadJS提供公式追踪功能,但原生上未绑定 ctrl+[ 或者 ctrl+] 快捷键,
需要您调研进行二次开发实现。
公式追踪相关内容您可以参考学习指南:
https://demo.grapecity.com.cn/sp ... et-dependent/purejs
绑定快捷键:
https://demo.grapecity.com.cn/sp ... ions/sheet-actions#
https://gcdn.grapecity.com.cn/showtopic-87326-1-1.html

您也可以在论坛搜索相关知识,获取更多信息。
回复 使用道具 举报
Derrick.Jiao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2021-9-17 16:41:23
18#
chezhijun 发表于 2021-9-17 16:29
好的感谢。我这边再尝试一下

如果有新的问题建议您开一个新帖交流哈,这样避免盖楼过多影响沟通的效率
回复 使用道具 举报
chezhijun
金牌服务用户   /  发表于:2021-9-17 16:29:23
17#
好的感谢。我这边再尝试一下
回复 使用道具 举报
Derrick.Jiao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2021-9-17 16:13:20
16#
chezhijun 发表于 2021-9-17 15:36
好的,感谢说明。这边遇到一个问题是,我们引入 spreadjs 的时候没有将公式栏额外引入,整个 spread 是作为 ...

上面的demo为了演示效果更加清楚才加的 formulaTextBox ,如果您没有使用 formulaTextBox那就把这块逻辑去掉即可,不必过多关注这个额外的因素。核心就在如何写这个命令和注册命令。
回复 使用道具 举报
chezhijun
金牌服务用户   /  发表于:2021-9-17 15:36:28
15#
好的,感谢说明。这边遇到一个问题是,我们引入 spreadjs 的时候没有将公式栏额外引入,整个 spread 是作为一个整体的 HTML 元素引入的,请问这种情况下如何设定 formulaTextBox 的初始化参数?
回复 使用道具 举报
Derrick.Jiao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2021-9-17 11:51:25
14#
chezhijun 发表于 2021-9-17 10:08
抱歉时隔这么久再次回复,请问您提供的代码中 26 行和 27 行中的变量 fbx 代表什么?没看到这个变量的初始 ...

您可以下载附件看一下,fbx表示的是公式栏的示例,上面给您展示的代码只是该命令的核心代码,您可以到附件里面看下。
image.png745158385.png

有关更多fbx的信息可以参考下面的链接
https://demo.grapecity.com.cn/sp ... mula-textbox/purejs
回复 使用道具 举报
chezhijun
金牌服务用户   /  发表于:2021-9-17 10:08:53
13#
抱歉时隔这么久再次回复,请问您提供的代码中 26 行和 27 行中的变量 fbx 代表什么?没看到这个变量的初始化的地方
回复 使用道具 举报
Lynn.Dou讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2021-9-1 11:21:38
12#
公式栏文本未随之更改的原因是:
选择单元格,公示栏显示单元格value,
这一过程内部逻辑包含了几个步骤:
1、获取选择单元格的值
2、公式栏栏拿到value后重新赋值,修改显示值
3、取消单元格激活状态

所以通过API改变选择单元格时,也要通过代码实现公式栏value的更新。
主要代码如下:

  1. let command1 = {
  2.                 canUndo: false,
  3.                 execute: function(context, options, isUndo) {
  4.                     let Commands = GC.Spread.Sheets.Commands
  5.                     if (isUndo) {
  6.                         Commands.undoTransaction(context, options);
  7.                         return true;
  8.                     } else {
  9.                         Commands.startTransaction(context, options);
  10.                         let sheet = context.getActiveSheet()
  11.                         let rowIndex = sheet.getActiveRowIndex()
  12.                         let columnIndex = sheet.getActiveColumnIndex()
  13.                         let childNodes = sheet.getPrecedents(rowIndex, columnIndex)
  14.                         if (childNodes.length > 0) {
  15.                             sheet.clearSelection();
  16.                             for(let i=0; i<childNodes.length; i++) {
  17.                                 let targetNode = childNodes[i];
  18.                                 let targetSheet = context.getSheetFromName(targetNode.sheetName)
  19.                                 let targetRowIndex = targetNode.row
  20.                                 let targetColumnIndex = targetNode.col
  21.                                 context.setActiveSheet(targetNode.sheetName)
  22.                                 targetSheet.addSelection(targetRowIndex, targetColumnIndex, 1, 1)
  23.                                 if(i==0) {
  24.                                     targetSheet.setActiveCell(targetRowIndex, targetColumnIndex);
  25.                                     // 获取选择单元格的值,赋值到公式栏
  26.                                     fbx.text("" + targetSheet.getValue(targetRowIndex, targetColumnIndex));
  27.                                     fbx.refresh(true);
  28.                                     targetSheet.endEdit(true);
  29.                                 }
  30.                             }
  31.                         }

  32.                         Commands.endTransaction(context, options)
  33.                         return true
  34.                     }
  35.                     
  36.                 }
  37.             }

  38.             spread.commandManager().register("searchDependent", command1)
  39.             spread.commandManager().setShortcutKey("searchDependent", 219, true, false, false, false);
复制代码



具体请参考附件的demo(已添加公式栏)。
注:参考Excel快捷键形式对您提供的代码做了修改,
测试步骤:
选择B4单元格,按下ctrl+[ ,观察公式栏值变化

自定义快捷键.zip

5.42 MB, 下载次数: 52

回复 使用道具 举报
Lynn.Dou讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2021-8-31 17:24:42
11#
这边尝试根据您的代码整理一个demo,需要一定的时间,
待有进展会在本贴与您沟通。
回复 使用道具 举报
chezhijun
金牌服务用户   /  发表于:2021-8-31 16:51:37
10#
您好,您提供的 demo 文件里没有公式栏,无法复现这个问题。

关于我们绑定公式追踪的快捷键部分的代码如下

  1. let command1 = {
  2.                 canUndo: false,
  3.                 execute: function(context, options, isUndo) {
  4.                     let Commands = GC.Spread.Sheets.Commands
  5.                     if (isUndo) {
  6.                         Commands = undoTransaction(context, options)
  7.                     } else {
  8.                         Commands = startTransaction(context, options)
  9.                     }

  10.                     let sheet = context.getActiveSheet()
  11.                     let rowIndex = sheet.getActiveRowIndex()
  12.                     let columnIndex = sheet.getActiveColumnIndex()
  13.                     let childNodes = sheet.getDependents(rowIndex, columnIndex)
  14.                     if (childNodes.length > 0) {
  15.                         let targetNode = childNodes[0]
  16.                         let targetSheet = context.getSheetFromName(targetNode.sheetName)
  17.                         let targetRowIndex = targetNode.row
  18.                         let targetColumnIndex = targetNode.col
  19.                         context.setActiveSheet(targetNode.sheetName)
  20.                         targetSheet.setSelection(targetRowIndex, targetColumnIndex, 1, 1)
  21.                         targetSheet.setActiveCell(targetRowIndex, targetColumnIndex)
  22.                     }

  23.                     Commands.endTransaction(context, options)
  24.                     return true
  25.                 }
  26.             }

  27.             spread.commandManager().register("searchDependent", command1)
  28.             spread.commandManager().setShortcutKey("searchDependent", 219, true, false, false, false)

  29.             let command2 = {
  30.                 canUndo: false,
  31.                 execute: function(context, options, isUndo) {
  32.                     let Commands = GC.Spread.Sheets.Commands
  33.                     if (isUndo) {
  34.                         Commands = undoTransaction(context, options)
  35.                     } else {
  36.                         Commands = startTransaction(context, options)
  37.                     }

  38.                     let sheet = context.getActiveSheet()
  39.                     let rowIndex = sheet.getActiveRowIndex()
  40.                     let columnIndex = sheet.getActiveColumnIndex()
  41.                     let parentNodes = sheet.getPrecedents(rowIndex, columnIndex)
  42.                     if (parentNodes.length > 0) {
  43.                         let targetNode = parentNodes[0]
  44.                         let targetSheet = context.getSheetFromName(targetNode.sheetName)
  45.                         let targetRowIndex = targetNode.row
  46.                         let targetColumnIndex = targetNode.col
  47.                         context.setActiveSheet(targetNode.sheetName)
  48.                         targetSheet.setSelection(targetRowIndex, targetColumnIndex, 1, 1)
  49.                         targetSheet.setActiveCell(targetRowIndex, targetColumnIndex)
  50.                     }

  51.                     Commands.endTransaction(context, options)
  52.                     return true
  53.                 }
  54.             }

  55.             spread.commandManager().register("searchPrecedent", command2)
  56.             spread.commandManager().setShortcutKey("searchPrecedent", 221, true, false, false, false)
复制代码
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部