【发布时间】:2021-12-19 15:01:47
【问题描述】:
我只想将值(不是公式)从源范围复制并粘贴到目标,而没有重复项(某些值已经在目标范围内)。我尝试在网上按照几个教程从复制粘贴部分开始(甚至不是唯一条件),但不断收到错误“参数(字符串、数字、数字、数字)与 SpreadsheetApp 的方法签名不匹配.Spreadsheet.getRange ..."。不知道为什么,因为我使用的是相同的代码。还尝试了使用 copyTo 而不是 setValues 的方法,但得到了同样的错误。
function paste() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var source = spreadsheet.getDataRange();
var sourceValues = source.getValues();
var rowCount = sourceValues.length;
var columnCount = sourceValues[0].length;
var target = spreadsheet.getRange(1,4, rowCount, columnCount);
target.setValues(sourceValues);
}
这是我想要得到的sample spreadsheet。 我知道使用公式会更容易,但问题是我在 Source 中的数据是动态的,因为它来自 ImportXML,所以有时提取的数据会消失,这就是为什么我想在它们丢失之前只粘贴值。
【问题讨论】:
-
仅使用您在问题中显示的代码显示错误。见minimal reproducible example
-
这种类型的问题通常很容易解决,方法是使用调试器单步执行脚本并查看每个中间步骤的结果。在某些情况下,您可能必须创建中间变量才能在调试器中查看数据。一旦你学会了如何使用调试器,你会发现对这些问题的需求大大减少了。学习如何编码需要学习如何调试。
标签: google-apps-script google-sheets spreadsheet copy-paste