Google电子表格:将脚本分配给带有参数的按钮 [英] Google spreadsheets: Assign a script to a button with parameters

查看:59
本文介绍了Google电子表格:将脚本分配给带有参数的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以成功地将脚本分配给Google电子表格中的图像.我的问题是参数传递.

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.

很多tx.

推荐答案

对不起,但这确实不能解决我的问题.我不希望用户输入.这个想法是让每个单元都有一个关联的按钮.用户只需按下一个按钮,单元格就会充满时间戳.如果用户必须输入单元名称,则该名称已损坏.当前的解决方案有效,但是很丑陋:

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...

然后我将脚本TimeB12关联到单元格B12旁边的按钮,依此类推.

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

这篇关于Google电子表格:将脚本分配给带有参数的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆