如何在谷歌脚本中调试电子表格自定义函数? [英] How to debug a spreadsheet custom function in google script?

查看:126
本文介绍了如何在谷歌脚本中调试电子表格自定义函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个自定义函数用于电子表格,我希望能够至少显示一些数据。几乎没有什么东西可以工作,例如 Browser.msgBox 没有找到适当的权限。



断点不会中断执行。



我对这段代码有一些希望

  function test(){
var s =test
Logger.log(s)
return s + s
}

但是,当我将电子表格中的单元格设置为= test()单元格正确显示值testtest,但当我返回到脚本编辑器并使用view>执行转录或 view> logs 我什么也没看到。



也许这个日志记录会转到某个特定的文件?

解决方案

当您将自定义函数用作公式时,可以多次评估和重新评估它。因此,用此填写日志记录输出或执行脚本是不合适的。如果您想调试,您必须从脚本编辑器手动运行(或调试)脚本。

举一个例子,您有两个自定义函数 - f1() f2 ()
然后,在单元格 A1 中输入公式 = f1()并在 A2 中,输入 = f2(A1)
在这种情况下,这两个单元格将被重新评估。那么记录仪输出应该显示什么?


I am writing a custom function to be used in a spreadsheet and I would like to be able to at least display some data. Few things seem to work, for example Browser.msgBox doesn't find the appropriate permissions.

Breakpoints don't interrupt execution.

I had some hope for this code

function test() {
  var s = "test"
  Logger.log(s)
  return s + s
}

But when I set a cell in the spreadsheet to "=test()" the cell properly shows the value "testtest" but when I return to the script editor and use view>execution transcript or view>logs I don't see anything.

Perhaps this logging goes to a special file somewhere?

解决方案

When you use a custom function as a formula, it can be evaluated and re-evaluated at many times. Therefore, it is not appropriate to fill up the Logging output or the Execution Transcript with this. If you want to debug, you must run (or debug) the script manually from the script editor.

Take an example, where you have two custom functions - f1() and f2() And say, in cell A1, you enter the formula =f1() and in A2, you enter =f2(A1). In such a case, both the cells will be re-evaluated. So what should the logger output show ?

这篇关于如何在谷歌脚本中调试电子表格自定义函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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