How do I create an Auto-Clear Script in a Google Spreadsheet?

后端 未结 2 1858
遥遥无期
遥遥无期 2020-12-29 16:00

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

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-29 16:35

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

    1. Where is says 'Sheet1' you would use 'Lunch' which is the name of your sheet in your example.
    2. In the Script Editor, you can add a new trigger to have the script run every night.
      • In the Script Editor, go to the top menu "Resources » Current Project's Triggers"
      • Click the link "No triggers set up. Click here to add one now."
      • Make sure you set these values:
      • Run » clearRange
      • Events » Time-driven
        • Day Timer
        • Midnight to 1 am

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

    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.

    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.

提交回复
热议问题