我正在开发一个
的功能这是我到目前为止所得到的:
function moveRowsBasedOnCellValue(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var master = ss.getSheetByName('Main');
var values = master.getDataRange().getValues(); //selects all values in a sheet
values.forEach(function(value){
//if cell in the column H equals YES execute the script
if (value[7] == "YES"){
//variable to select all columns in the source sheet that aren't blank
var colWidth = master.getMaxColumns();
//variable containing the target sheet
var destinationYeses = ss.getSheetByName("Yeses");
//select first empty row in the destination sheet
var destinationYesesRange = destinationYeses.getRange(destinationYeses.getLastRow()+1,1);
//copy the relevant row into the sheet
master.getRange(value,1, 1, colWidth).copyTo(destinationYesesRange);
}});
}
脚本执行正常,直到脚本的最后一行:
master.getRange(value,1, 1, colWidth).copyTo(destinationYesesRange);
错误说明:
Cannot convert [here the Logger error provides a list of all values in a row separated by a comma] to (class).
对我可能做错了什么的想法?
答案 0 :(得分:2)
您收到该错误的原因如下:
from fabric import network
from fabric.state import connections
def reconnect_current_host():
network.disconnect_all()
connections.connect(env.host + ':%s' % env.port)
getRange期望传递给它的所有值都是整数。而value变量是一个数组。因此,为了解决这个问题,您必须进行以下两项更改
master.getRange(value,1, 1, colWidth).copyTo(destinationYesesRange);
第二
values.forEach(function(value,index){ // gives the array index to index variable
所以你的最终代码将如下所示:
//Index for array(values) starts at 0, whereas for the rows number in sheet starts at 1.
//so add 1 to convert the index to row number
master.getRange(index + 1,1, 1, colWidth).copyTo(destinationYesesRange);
最后注意事项:这是一种非常低效的数据传输方式,如果要复制大量数据并且脚本执行时间超过5-6分钟,则执行将终止。查看此帖addresses this issue
答案 1 :(得分:2)