英文:
Timestamp in Google sheets
问题
尝试创建一个时间戳脚本
嗨,我正在尝试创建一个时间戳脚本,每当在同一行中更改单元格时,它都会将日期放入A列。这适用于从列D到Y的所有列。
行的范围是从4到28。
我找到了这个代码,但对于我来说,列和行的范围不太清楚...所以请帮忙看一下。
function onEdit(e){
const sh = e.source.getActiveSheet();
sh.getRange('A' + e.range.rowStart)
.setValue(new Date())
.setNumberFormat('dd/MM HH:MM');
}
英文:
trying to make a timestamp script
Hi, I'm trying to make a timestamp script which puts the date in column A everytime a cell, in the same row, is changed. This for COLUMNS D to Y.
The range of rows is 4 to 28
I found this but the range in columns and rows is not clear for me... so please help
function onEdit(e){
const sh = e.source.getActiveSheet();
sh.getRange ('A' + e.range.rowStart)
.setValue (new Date())
.setNumberFormat ('dd/MM HH:MM');
}
答案1
得分: 0
我相信您的目标如下。
- 当编辑"D4:Y28"中的单元格时,您希望在编辑的单元格所在行的"A"列中放置一个日期。
在您的脚本中,所有单元格都被使用。所以,在这种情况下,以下修改如何?
修改后的脚本:
function onEdit(e) {
const sheetName = "Sheet1"; // 请设置您的工作表名称。
const { range } = e;
const sheet = range.getSheet();
if (
sheet.getSheetName() != sheetName ||
range.columnStart < 4 ||
range.columnStart > 25 ||
range.rowStart < 4 ||
range.rowStart > 28
) return;
sheet.getRange(range.rowStart, 1).setValue(new Date()).setNumberFormat('dd/MM HH:MM');
}
- 在这种修改中,只有当编辑"D4:Y28"中的单元格时,才会在编辑的单元格所在行的"A"列中放置日期。
参考资料:
英文:
I believe your goal is as follows.
- When a cell in "D4:Y28" is edited, you want to put a date in column "A" of the same row with the edited cell.
In your script, all cells are used. So, in this case, how about the following modification?
Modified script:
function onEdit(e) {
const sheetName = "Sheet1"; // Please set your sheet name.
const { range } = e;
const sheet = range.getSheet();
if (
sheet.getSheetName() != sheetName ||
range.columnStart < 4 ||
range.columnStart > 25 ||
range.rowStart < 4 ||
range.rowStart > 28
) return;
sheet.getRange(range.rowStart, 1).setValue(new Date()).setNumberFormat('dd/MM HH:MM');
}
- In this modification, only when a cell in "D4:Y28" is edited, a date is put into column "A" of the same row with the edited cell.
References:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论