Google apps script 如何设置值(),当它';google应用程序脚本中有整行吗?

Google apps script 如何设置值(),当它';google应用程序脚本中有整行吗?,google-apps-script,google-sheets,setvalue,Google Apps Script,Google Sheets,Setvalue,我一直在尝试运行这一个,尽管currentRow大约有23列,但我只设置了第一列的值: targetSheet.setActiveRange(targetSheet.getRange(maxIndex + 2, 1)) .setValue(currentRow); 我尝试了seValues(),但它不起作用 以下是当前记录的行: 有灯光吗?更新答案: 如果有一维阵列,则将其设为二维: targetSheet.getRange(maxIndex + 2,1,1,currentRow.leng

我一直在尝试运行这一个,尽管currentRow大约有23列,但我只设置了第一列的值:

targetSheet.setActiveRange(targetSheet.getRange(maxIndex + 2, 1))
 .setValue(currentRow);
我尝试了seValues(),但它不起作用

以下是当前记录的行:


有灯光吗?

更新答案:

如果有一维阵列,则将其设为二维:

targetSheet.getRange(maxIndex + 2,1,1,currentRow.length).setValues([currentRow])

  • 您不需要活动范围,可以直接粘贴数据
  • 如果要使用
    setValues
    在工作表中粘贴多个值,则输入
    currentRow
    需要是一个2D数组(是
    getValues
    的结果)
以下示例复制
A1:W1
中的值,并将其粘贴到
A2:W2

function myFunction() {
  const ss = SpreadsheetApp.getActive();
  const targetSheet = ss.getSheetByName('target'); // put the name of your sheet
  const currentRow = targetSheet.getRange(1,1,1,23).getValues(); // range A1:W1
  targetSheet.getRange(2,1,1,23).setValues(currentRow); // set values to A2:W2
}

1.什么是当前行
console.log(currentRow)
告诉我们它包含什么2。您不需要
setActiveRange
,您可以在不激活任何范围3的情况下设置值。我猜您尝试了
setValues()
而不是
seValues()
;检查我的更新答案,如果它适合你。假设
maxIndex
是一个数字。