gpt4 book ai didi

javascript - 转置数组时出现 “This operation is not supported from a callback function” 错误

转载 作者:行者123 更新时间:2023-12-03 16:32:58 24 4
gpt4 key购买 nike

首先对这个问题表示歉意,但 GAS 对我来说是一种新语法。我想做一些在 VBA 语法中很简单的事情,但在 GAS 中却不行。

我想在不同的工作表上将一个命名范围转置为另一个命名范围(例如,从 4 行到 4 列)。网络上有使用 .getDataRange() 的示例,但我希望使用固定的命名范围,无论其中是否包含数据。

我使用的语法如下:

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 行到记录集/数据库工作表 (wksDB) 最后一行的 4 列

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 脚本调试器无法按设计执行回调,因此在调试代码时,不要执行调试步骤,而是在之前放置一个断点并在调用转置函数之后使调试器跳过该调用。

引用资料

在 Google Apps Script Issues 中有一个关于此的问题 -> Issue 4662: Debug breakpoint within the function body of an Array.map() call causes a server error有来自 Google 员工的以下评论

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

This is currently working as intended -- we do not support debuggerbreakpoints withing callback functions. This issue will therefore bemarked as a Feature request.

一个没有答案的相关问题,但有帮助我找到上述引用的信息性评论

Debugger fails with "This operation is not supported from a callback function."

关于javascript - 转置数组时出现 “This operation is not supported from a callback function” 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32619480/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com