我想以此作为序言,因为我没有接受过这一专业领域的培训,因此我帮助设置了该表的初始代码。我设置了工作表,以便在 A 列和 C 列中添加复选框,并在 B 和 D 中添加时间戳,但我也希望这样,如果需要取消选中复选框,则数据将被删除。
A B C D
复选框|时间戳|复选框|时间戳
我有以下内容,但如果未选中 A 或 C,我不确定从这里到哪里实际删除 B 或 D 中的数据。我不确定在删除部分中输入什么是正确的
非常非常感谢任何帮助!
function myFunction() {
// get the active sheet so you can check if the checkbox in the current cell is checked
// get the selected cell on the sheet
// get the coordinates of the cell to write the date/time to
var activeSheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var activeCell = activeSheet.getCurrentCell();
var nextCol = activeCell.offset(0, 1);
// if the checkbox in the current cell is checked, then write date and time
// into the cell immediately to the right of the checked cell
// after a box is checked and the date/time are written into the cell next to it,
// do not allow that cell to be updated in the future regardless of the state
// of the checkbox being changed
if (activeCell.isChecked()) {
// get the date object in order to find date and time
var date = new Date();
// write the date and time only if the cell next to the active cell is empty
if (nextCol.getValue() === '') {
nextCol.setValue(date.toLocaleDateString() + ' ' + date.toLocaleTimeString());
}
}
// if the checkbox is unchecked and there's text in the column next to it, then remomve the text in the column
if (!activeCell.isChecked();
值得一提的是,这可以在没有脚本的情况下完成,例如对于 A1 中的复选框,您可以使用以下命令在 B1 中生成静态时间戳:
=if(A1,lambda(x,x)(now()),)
当第一次勾选 A1 时,LAMBDA 需要使 NOW() 保持“粘性”,否则在工作表中的每次编辑时都会重新评估它。取消选中 A1 将删除时间戳。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)