Google apps script Google sheet脚本独立地从源单元格复制值

Google apps script Google sheet脚本独立地从源单元格复制值,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我需要一个google sheet脚本函数,在我的单元格中复制另一个单元格中公式的结果。 我需要单元格获得第一个结果,然后独立于其他单元格,因为公式结果可以变成N/D,但我需要第二个单元格保留该值 您可以在另一个给定单元格中复制公式的输出: 这里有一个例子: /** * The column B hosts the formulas and the column A hosts the output */ function myFunction() { let ss = Spreadshee

我需要一个google sheet脚本函数,在我的单元格中复制另一个单元格中公式的结果。

我需要单元格获得第一个结果,然后独立于其他单元格,因为公式结果可以变成N/D,但我需要第二个单元格保留该值

您可以在另一个给定单元格中复制公式的输出: 这里有一个例子:

/**
* The column B hosts the formulas and the column A hosts the output
*/
function myFunction() {
  let ss = SpreadsheetApp.getActiveSheet();
  ss.getRange("A1").setValue(ss.getRange("B1").getValue());
}
编辑: 要复制范围,请使用
.setValues()
.getValues()
函数:

function myFunction() {
  let ss = SpreadsheetApp.getActiveSheet();
  ss.getRange("A1:A").setValues(ss.getRange("B1:B").getValues());
}
参考资料:

嗨!谢谢你的剧本。你能把它调整到复制A中的整个B列吗;我试着用A1:A1000代替A1和B1,但它只复制了整个专栏中的第一个。编辑了问题以回应你的评论。太好了,5天后我的问题就解决了。你真的帮了我很多。