[英]Google sheets - Update date cells based on criteria
我需要每周更新一次工作表中的日期。
我想手动运行一个脚本来做到这一点。
“C”列中的每个日期将在同一行的“D”列中增加天数。 仅更新特定单元格中日期之前的日期(例如 F2)。
以这张表为例: https://docs.google.com/spreadsheets/d/11f6G5_vNK5Z8UR2A_MUUXpL8awC2mJ8ozpnznWQ_anM/edit?usp=sharing
列 C - 服务日期 | D 栏 - 提前天数 |
---|---|
2021 年 12 月 3 日 | 7 |
2021 年 12 月 3 日 | 14 |
2021 年 12 月 10 日 | 7 |
2021 年 12 月 10 日 | 7 |
2021 年 12 月 17 日 | 28 |
我读过很多帖子,但对这些类型的脚本非常陌生。 任何帮助或指向正确的方向都会很棒!
谢谢,戴夫
function updateDates() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName('Sheet0');
const vs = sh.getRange(2,1,sh.getLastRow() - 1, sh.getLastColumn()).getValues();
const dt = new Date(sh.getRange('F2').getValue());
const dthv = new Date(dt.getFullYear(),dt.getMonth(),dt.getDate()).valueOf();
const oA = [];
vs.forEach(r => {
let d = new Date(r[2]);
let dv = new Date(d.getFullYear(),d.getMonth(),d.getDate()).valueOf()
if(dv < dthv) {
oA.push([new Date(d.getFullYear(),d.getMonth(),d.getDate() + r[3])])
} else {
oA.push([r[2]]);
}
});
sh.getRange(2,3,oA.length,oA[0].length).setValues(oA);
}
下面来自 Copper 的脚本就像一个魅力。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.