我想先說明一個事實,即我幫助設定了作業表的初始代碼,因為我沒有在這個專業領域接受過培訓。我設定了我的作業表,以便我在 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();
uj5u.com熱心網友回復:
值得一提的是,這可以在沒有腳本的情況下完成,例如,對于 A1 中的復選框,您可以使用以下代碼在 B1 中生成靜態時間戳:
=if(A1,lambda(x,x)(now()),)
LAMBDA 需要在首次勾選 A1 時使 NOW() “粘性”,否則在作業表中的每次編輯時都會重新評估。取消勾選 A1 會洗掉時間戳。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/537026.html
