Based on my understanding, you want to get the cell row of the drawing that is being clicked to include the time entry for a particular student.
That is not possible, when you click a drawing/image, you are only clicking the drawing/image. It doesn't make the cell where the image located be active. Therefore, we cannot use the getActiveRange
and getSelection
method to locate the cell where the image is located.
One workaround that I could think of is to use checkboxes instead of drawings. When checkboxes are clicked, it makes the cell active.
Sample Code:
function onEdit(e) {
const sheet = e.source.getActiveSheet();
const cell = e.range
// Check if checkbox was checked and there is no time-entry yet
if (cell.isChecked() == true && cell.offset(0,-1).isBlank()){
//Include time entry on the left side of the checkbox
//var date = Utilities.formatDate(new Date(), 'America/Los_Angeles', 'MMMM dd, yyyy HH:mm:ss Z');
var date = Utilities.formatDate(new Date(), 'America/Los_Angeles', 'HH:mm:ss Z');
cell.offset(0,-1).setValue(date);
// Uncheck the checkbox
cell.setValue(false);
} else if (cell.isChecked() == true) {
// Uncheck the checkbox
cell.setValue(false);
}
}
You can change the format of your timestamp depending on your preference. In this example I only displayed the current time. See Working with Dates and Times
Output:
I reset the checkbox after setting the timestamp.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…