如何在一个谷歌小号preadsheet创建一个自动清除脚本? [英] How do I create an Auto-Clear Script in a Google Spreadsheet?

查看:261
本文介绍了如何在一个谷歌小号preadsheet创建一个自动清除脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以利用一些帮助,在我的谷歌小号preadsheet写剧本。首先,我不是程序员,充其量写作code或任何脚本新手。

I could use some help with writing a script in my Google spreadsheet. First off, I am no programmer and a novice at best on writing code or any script.

我想用这个的午餐名单。后面的故事:我创建了谷歌小号preadsheets作为数字午餐表。每一位教师都有自己的目的preadsheet他们的班主任和班级的总数为填充头食堂工人的订购为主午餐表。问题是旧的总数仍然从前一天present。在S preadsheet理想情况下,新的一天的开始,在指定的字段将自动清除。 <一href=\"https://docs.google.com/s$p$padsheet/ccc?key=0AigfwqBbSV6CdHZCX21vVXBHaVdqVG1nOENvZEx0MVE&usp=sharing\"相对=nofollow>点击这里查看我创建在S preadsheet的一个例子。

I want to use this for a lunch list. The back story: I created Google spreadsheets to act as a digital lunch sheet. Each teacher has their own spreadsheet for their homeroom and the totals for the class populate a master lunch sheet for the head cafeteria worker for ordering. The problem is that the old totals are still present from the day before. Ideally, on the start of a new day, the specified fields on the spreadsheet will auto clear. Click here to view an example of the spreadsheet I created.

在我的研究,我发现了如何创建一个脚本来做到这一点线索,但作为一个按钮单击,然后将明确指定的范围<一个href=\"http://stackoverflow.com/questions/9268570/i-need-a-button-to-clear-cells-in-a-google-s$p$padsheet\">Click这里查看原帖。作为后面的脚本:

In my research I found a thread on how to create a script to do this, but as a button to click that will then clear specified ranges Click here to see the original post. The script is as followed:

function clearRange() {
  //replace 'Sheet1' with your actual sheet name
  var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
  sheet.getRange('C4:I12').clearContent();}

我想为有是一个脚本,这样每天(在每天午夜说吧)的特定字段/范围清除出去。 我不希望列或行删除,因为我不想失去学生姓名或午餐选择。

What I would like for is there to be a script so that everyday (say everyday at midnight) a specific field/ range is cleared out. I do not want columns or rows to delete because I do not want to lose student names or lunch selections.

请,任何帮助是极大的AP preciated。在此先感谢您的帮助,特别是像我这样一个新手。我期待着听到任何人!
结果,贾森 -

Please, any help is greatly appreciated. Thanks in advance for your help, especially with a novice like me. I look forward to hearing from anyone!
- Jason

推荐答案

该脚本应该做你所需要的。你只需要做一些修改。

That script should do what you need. You just need to make a couple of modifications.


  1. 哪里是说'工作表Sheet1你会用'午餐',这是你的表在你的榜样的名称。

  2. 在脚本编辑器,你可以添加一个新的触发每天晚上运行脚本。

    • 在脚本编辑器,进入顶部菜单资源»当前项目的触发器

    • 点击链接无触发成立。点击此处添加一个了。

    • 确保设置这些值:

    • 运行»clearRange

    • 活动»时间驱动

      • 天定时

      • 午夜到凌晨1点

这应该午夜之间每天晚上运行脚本,有时凌晨1点。

That should run your script every night sometime between Midnight to 1 AM.

如果你想,你可以在S preadsheet内点击,所以你可以运行你想要的脚本随时随地实际的菜单项,这是一个有点更多的工作。老实说,如果这是你的主要功能......它可能只是更容易从S preadsheet(工具»脚本编辑器)加载脚本编辑器,而只需选择clearRange功能和preSS播放按钮

If you want an actual menu item that you can click on within the spreadsheet so you can run the script anytime you want, that's a bit more work. Honestly, if that's your primary function ... it's probably just easier to load up the Script Editor from the spreadsheet ("Tools » Script Editor"), and just select the clearRange function and press the play button.

如果你真的想添加菜单项,还有这里的其他文档»<一个href=\"https://developers.google.com/apps-script/reference/s$p$padsheet/s$p$padsheet#addMenu(String,Object)\" rel=\"nofollow\">https://developers.google.com/apps-script/reference/s$p$padsheet/s$p$padsheet#addMenu(String,Object).一旦你codeD的新菜单功能,你就必须更新你的触发器就像你每天晚上运行。但是相反,你会改变事件类型为从s preadsheet 和值设置为在打开 。这样,在S preadsheet打开时,它会创建新的菜单项。

If you do really want to add menu items, there's additional documentation here » https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet#addMenu(String,Object). Once you've coded the new menu function, you'll have to update your triggers just like you did to run every night. But instead, you'll change the event type to From Spreadsheet and set the value to On open. That way it'll create the new menu items when the Spreadsheet is opened.

这篇关于如何在一个谷歌小号preadsheet创建一个自动清除脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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