简体   繁体   English

如何在Google脚本中调试电子表格自定义功能?

[英]How to debug a spreadsheet custom function in google script?

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. 似乎没有什么效果,例如Browser.msgBox找不到适当的权限。

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. 但是,当我在电子表格中将一个单元格设置为"=test()"该单元格会正确显示值“ testtest”,但是当我返回脚本编辑器并使用view> execution transcript或view>logs我什么也看不到。

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) . 例如,您有两个自定义函数f1()f2()并说,在单元格A1 ,输入公式=f1() ,在A2 ,输入=f2(A1) In such a case, both the cells will be re-evaluated. 在这种情况下,两个单元都将被重新评估。 So what should the logger output show ? 那么记录器输出应该显示什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM