我可以在Google Apps脚本的撤消堆栈中排除操作吗? [英] Can I exclude operations from the undo stack in Google Apps Script?

查看:72
本文介绍了我可以在Google Apps脚本的撤消堆栈中排除操作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个功能,每当进行编辑时,便会从一张纸上读取笔记并将它们写到另一张纸的单元格中.但是,每当执行此操作时,它会将所有这些写操作添加到撤消堆栈中.这意味着每当用户进行编辑时,就不再可以使用撤消功能,因为撤消堆栈中充满了脚本所做的编辑.

I have a function which reads notes from one sheet and writes them into cells in another sheet whenever an edit is made. However, whenever I do this, it adds all those writes to the undo stack. This means that whenever the user makes and edit, it's no longer possible to use the undo feature, as the undo stack is full of the edits the script has made.

是否可以从撤消堆栈中排除脚本执行的写功能?我很欣赏这可能无法实现,但是如果我不能做到这一点,我将不得不使用计时器每小时运行一次,这意味着一切都将过时一个小时.

Is there a way to exclude the write functions that the script does from the undo stack? I appreciate this may not be possible, but if I can't do that I'll have to do an hourly run using the timer, and this means everything will be up to an hour out of date.

干杯

迈克

推荐答案

不幸的是,脚本所做的操作等同于您自己在单元格中编写某些内容.在工作表侧跟踪编辑堆栈,并由运行脚本的用户进行编辑.

Sadly, the operation the script does is equivalent to you writing something in a cell yourself. The edit stack is tracked on the Sheet side and the edits are made by the user running the script.

您唯一的希望就是以与打开电子表格的用户不同的用户身份运行它,但是鉴于onEdit()触发器的性质,这可能是不可能的.请参阅触发器文档.

Your only hope would be to run it as a different user than the one that has opened the spreadsheet, but that may not be possible given the nature of onEdit() triggers. See the trigger documentation.

我建议这样做的原因是工作表会分别跟踪每个用户的编辑.但是,即使这不是一个完美的解决方案,就像我们都编辑完全相同的单元格一样,撤消操作仍然会更改您所做的任何修改.例如,如果我将A写入一个空单元格,然后又将B写入同一单元格,则我按下undo,它将再次成为一个空单元格.

The reason I suggest this is that sheets tracks each users edits separately. However even this is not a perfect solution as if we both edit the exact same cell, my undo will still change whatever your edits were. E.G if I write A into an empty cell, and you then write B into that same cell, one I hit undo, it will be an empty cell again.

这篇关于我可以在Google Apps脚本的撤消堆栈中排除操作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆