Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google spreadsheets: Assign a script to a button with parameters

I can successfully assign scripts to images in Google spreadsheets. My problem is with parameter passing.

I have this script to write the current time on a cell.

function Time(cell){
  var  d = new Date();
  var timeAsString = d.getHours() + ":" + d.getMinutes() + "/" + d.getSeconds();

  SpreadsheetApp.getActiveSheet().getRange(cell).setValue(timeAsString); 
};

I need a bunch of buttons to do this with diferent cells, so I wish to specify which cell the time goes to by parameter.

Many tx.

like image 565
Patrakula Avatar asked Feb 23 '15 16:02

Patrakula


1 Answers

Sorry, but this really doesn't solve my problem. I don't want user input. The idea is to have a button associated to each cell. The user just presses a button and the cell is filled with a timestamp. If the user must input the cell name, it's ruined. Current solution works but it's ugly:

function Time(cell){
  var  d = new Date();
  var timeAsString = d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
  SpreadsheetApp.getActiveSheet().getRange(cell).setValue(timeAsString); 
};

function TimeB12(){Time('B12')};
function TimeB13(){Time('B13')};

// about 500 more cells...

I then associate script TimeB12 to button next to cell B12, and so on.

like image 188
Patrakula Avatar answered Sep 21 '22 20:09

Patrakula