[英]Is there a way to iterate a formula across cells in a multiple selection - Google sheet
In a google sheet, this simple script works to select a single cell, then click a button to decrease the value in the selected cell by 1:在谷歌表中,这个简单的脚本适用于 select 单个单元格,然后单击按钮将所选单元格中的值减 1:
function tally() {
var cell = SpreadsheetApp.getActiveSheet().getActiveCell();
var value = cell.getValue();
cell.setValue(value-1);
}
Is there a way to do a multiple selection - ie, select multiple / scattered cells in a table, then iterate the function in each of the selected cells?有没有办法进行多项选择 - 即 select 表格中的多个/分散的单元格,然后在每个选定的单元格中迭代 function ?
function tally() {
const rng = SpreadsheetApp.getActiveSheet().getActiveRange();
const values = rng.getValues().map(r=>r.map(c=>c-1));
rng.setValues(values);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.