Google Apps Script Sheets onClick Event put an X i

2019-08-10 10:34发布

问题:

I see there is not a great way to create a checkbox in Google sheets. Is there a way with a script for an X or checkmark to get placed in a cell when the cell is clicked? I'd like the script to work for all cells in column 5.

回答1:

No there isnt. You can use a menu to put the X on the selected cell but not on cell click.



回答2:

Is there a way to have the time auto fill in a cell when it is clicked? I use the following script to auto fill time when the cell to the left is edited.

function onEdit(e) {
  var s = e.source.getActiveSheet(), r, colCell, nextCell;
  if(s.getName() === 'SignInOut') { //checks that we're on the correct sheet
    r = e.range; //s.getActiveCell();
    colCell = r.getColumn();
    if(colCell === 3 || colCell === 5) { //checks the column
      nextCell = r.offset(0, 1);
      if(nextCell.getValue() === '') //is empty?
        nextCell.setValue(new Date());
    }
  }
}