How to debug a spreadsheet custom function in goog

2019-06-24 03:49发布

问题:

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?

回答1:

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 ?