简体   繁体   English

在Google电子表格中放置一个“开始”按钮

[英]Put a “Start” button in Google spreadsheet

I am very a newbie at programming... 我是编程的新手...

I want to insert a button called "Start" in my Google spreadsheet and when I click on it, I want that the date and time at that very moment go in another cell. 我想在Google电子表格中插入一个名为“开始”的按钮,当我单击它时,我希望当时的日期和时间进入另一个单元格。 So the function NOW() should be running and the value of it to be put in another cell... not sure I'm perfectly clear though... Please find attached an image that show how that would work. 因此,函数NOW()应该正在运行,并且它的值应该放在另一个单元格中……不确定我是否很清楚……请找到所附的图片,说明该方法的工作原理。

Thank you so much for you help! 非常感谢您的帮助!

enter image description here 在此处输入图片说明

The simple answer is that you can't really use google docs in that way. 简单的答案是,您不能真的那样使用google docs。 The more complicated answer is that you'll need to build an add-on through app scripting: https://developers.google.com/apps-script 更为复杂的答案是,您需要通过应用程序脚本构建附加组件: https : //developers.google.com/apps-script

Google states that their intended replacement of the ui scripting is now html: Google声明,他们打算将ui脚本替换为html:

https://developers.google.com/apps-script/guides/html/ https://developers.google.com/apps-script/guides/html/

so in other words, to make that button, you'll need to make an apps-script add-on and put that in your spreadsheet. 因此,换句话说,要创建该按钮,您需要制作一个apps-script插件并将其放入电子表格中。

I'm not actually in a place where I can check, but there used to be an insert menu where you could put an empty button-looking object on the sheet, then you might be able to attach a more simplified script to that object. 我实际上不在可以检查的地方,但是曾经有一个插入菜单,您可以在该菜单上放置一个空的按钮状对象,然后可以在该对象上附加一个更简化的脚本。 If that isn't around anymore, you'll have to go the apps-script direction. 如果这种情况不再存在,您将必须遵循apps-script的方向。

You can assign an Apps Script function to an image or drawing in Google Sheets, so long as the script is bound to the spreadsheet. 您可以将Apps脚本功能分配给Google表格中的图像或图形,只要脚本已绑定到电子表格即可。 The example below shows how to set this up. 下面的示例显示了如何进行设置。

  1. In Google Sheets, select the menu item Tools > Script editor to create a script that is bound to the spreadsheet. 在Google表格中,选择菜单项工具>脚本编辑器以创建绑定到电子表格的脚本。
  2. Paste in the code below. 粘贴下面的代码。
  function startDate() { var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(), cell = 1, col = 1, cellC = 1, colC = 1, rowData = new Date, pasteTo = sheet.getRange(cell, col,cellC,colC).setValue(rowData); } 
  1. Return to Sheets and insert an image or drawing by selecting Insert > Image or Insert > Drawing. 返回至图纸并通过选择插入>图像或插入>绘图来插入图像或绘图。
  2. After inserting the image or drawing, click it. 插入图像或图形后,单击它。 A small drop-down menu selector will appear in the top right-hand corner. 一个小的下拉菜单选择器将出现在右上角。 Click it and choose Assign script. 单击它,然后选择“分配脚本”。
  3. In the dialog box that appears, type the name of the Apps Script function that you want to run, without parentheses — in this case, startDate. 在出现的对话框中,键入要运行的Apps脚本函数的名称,不带括号-在本例中为startDate。 Click OK. 单击确定。
  4. Click the image or drawing again. 再次单击图像或绘图。 The function will now execute. 该函数现在将执行。

Please find here the document i'm using for now. 请在这里找到我正在使用的文档。

I definitely think I can improve that, because the problem with those multiple buttons is that my co-workers have to "authorize" the script each time the click on "Start" or "Stop", and that for all the projects. 我绝对认为我可以改善这一点,因为这多个按钮的问题是,每次单击“开始”或“停止”时,我的同事都必须“授权”脚本,并且必须针对所有项目进行“授权”。 So each time a select a task and click start button, it creates a new line in another tab with "Task", "Start time", "End time" 因此,每次选择一个任务并单击“开始”按钮时,它将在另一个选项卡中用“任务”,“开始时间”,“结束时间”创建新行

My ultimate goal would be to have a page with only 3 things - the list of tasks - START button - STOP button 我的最终目标是只有3个页面-任务列表-“开始”按钮-“停止”按钮

http://hpics.li/cc882f1 http://hpics.li/cc882f1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM