Google表格脚本可从源单元格中单独复制一个值

时间:2020-03-18 12:56:54

标签: google-apps-script google-sheets

我需要一个Google工作表脚本函数,该函数可以在单元格中复制另一个单元格中的公式结果。
我需要单元格来获得第一个结果,然后变得独立于另一个单元格,因为公式结果可以变为N / D,但是我需要第二个单元格来保留值。

1 个答案:

答案 0 :(得分:0)

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

/**
* 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());
}

参考文献:

getValue setValue getValues setValues