在转置数组时获取“回调函数不支持此操作”错误

在转置数组时获取“回调函数不支持此操作”错误

问题描述:

这个问题的第一道歉,但GAS是一个新的语法给我。
我想做一些简单的VBA语法,但不是在GAS。

First apologies for this question but GAS is a new syntax to me. I would like to do something that is simple in VBA syntax, but not in GAS.

我想将一个命名范围转置到另一个命名范围从4行到4列)在不同的工作表。在网络上有一些使用.getDataRange()的例子,但我想使用一个固定的命名范围,不管是否包含数据。

I want to transpose one named range to another named range (e.g. from 4 rows to 4 columns) on different worksheets. There are examples on the web that use .getDataRange() but I wish to use a fixed named range, whether there is data contained within or not.

玩弄以下是:

var wksInput = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('New');
var wksDB = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Database');
var intDBNewRow = wksDB.getLastRow() + 1;

wksDB.getRange(intDBNewRow, wksDB.getRange('dbContacts').getColumn(), 1,wksDB.getRange('dbContacts').getNumColumns()).setValues(transposeRange(wksInput.getRange('frmVanContacts').getValues())); 

从输入表单工作表(wksInput)上的固定点将4行放到最后一列的4列记录集/数据库工作表(wksDB)的行

Taking 4 rows from a fixed point on an input form worksheet (wksInput) to 4 columns on the last row of a recordset/database worksheet (wksDB)

其中 transposeRange 是:

function transposeRange(a)
{
  return Object.keys(a[0]).map(function (c) { return a.map(function (r) { return r[c]; }); });
}

错误是:


回调函数不支持此操作。

This operation is not supported from a callback function.

这里有什么问题?

回答



问题不在于转置功能,问题是Google Apps脚本调试器无法按设计步骤进入回调,因此,调试代码,而不是执行调试步骤,在调用转置函数之前和之后放置一个断点,以使调试器跳过该调用。

Answer

The problem isn't with the transpose function, the problem is that the Google Apps Script debugger can't do step into callbacks by design, so when debugging your code, instead of doing a debug step into, put a breakpoint before and after the call of the transpose function in order to make the debugger to skip that call.

在Google Apps脚本问题中,有一个问题 - > ,它从以下注释中获得了以下注释: Googler

In Google Apps Script Issues there is a issue about this -> Issue 4662: Debug breakpoint within the function body of an Array.map() call causes a server error that has the following comment from a Googler

https://code.google.com/p/google-apps-script-issues/issues/detail?id=4662#c3


这是目前正在工作的 - 我们不支持调试器
断点与回调函数。因此,此问题将
标记为功能请求。

This is currently working as intended -- we do not support debugger breakpoints withing callback functions. This issue will therefore be marked as a Feature request.

一个相关问题没有答案,帮助我找到上述参考

A related question with no answers yet but with informative comments that help me to find the above reference

调试器失败,并显示回调函数不支持此操作