如何在 Google 电子表格中创建自动清除脚本? [英] How do I create an Auto-Clear Script in a Google Spreadsheet?

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

问题描述

我可以借助一些帮助在我的 Google 电子表格中编写脚本.首先,我不是程序员,充其量也是编写代码或任何脚本的新手.

我想用这个做午餐清单.背景故事:我创建了 Google 电子表格来充当数字午餐表.每个老师都有自己的班级电子表格,班级的总数填充了主食堂工作人员的主午餐表以供订购.问题是前一天的旧总数仍然存在.理想情况下,在新的一天开始时,电子表格上的指定字段将自动清除.

02.粘贴此功能

function clearRange() {//用您的实际工作表名称替换Sheet1"//用您的实际工作表 ID 替换 'dhrhrejYOURSHETIDerhe5j54j5j'var sheetActive = SpreadsheetApp.openById("dhrhrejYOURSHETIDerhe5j54j5j").getSheetByName("Sheet1");sheetActive.getRange('A:Y').clearContent();}

ˢᵖʳᵉᵃᵈˢʰᵉᵉᵗᴵᴰᴱˣᵃᵐᵖˡᵉ

03.转到运行 &选择运行函数,然后选择clearRange.
运行脚本后,应清除电子表格.

如果它工作正常,请按照以下步骤...

04.转到编辑,选择所有触发器"

05.在所有触发器"弹出窗口中,选择clearRange 作为运行 函数.
06.随心所欲地设置时间.(见示例图片)

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.

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.

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.

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

解决方案

Follow these steps...

01. Go to https://script.google.com and then add a New Script.

ᴬᵈᵈ ⁿᵉʷ ˢᶜʳⁱᵖᵗ

02. Paste this function

function clearRange() {
      // replace 'Sheet1' with your actual sheet name
      // replace 'dhrhrejYOURSHETIDerhe5j54j5j' with your actual sheet ID

      var sheetActive = SpreadsheetApp.openById("dhrhrejYOURSHETIDerhe5j54j5j").getSheetByName("Sheet1");
      sheetActive.getRange('A:Y').clearContent();

    }

ˢᵖʳᵉᵃᵈˢʰᵉᵉᵗ ᴵᴰ ᴱˣᵃᵐᵖˡᵉ

03. Goto Run & select Run function and then select clearRange.
Once you have run the script, your spreadsheet should be cleared.  

Follow these steps if it works correctly...

04. Goto Edit, Select 'All your triggers'

05. In 'All your triggers' popup windows, select clearRange as the Run function.
06. Set the time as you like. (See the example image)

这篇关于如何在 Google 电子表格中创建自动清除脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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