Clear Google Spreadsheet content daily

Post date: Jan 19, 2011 4:43:31 PM

Recently a potential employer posted a Job on odesk, wanted a script to clear the Google Spreadsheet content daily using Google Spreadsheet PHP API. I told him about Google Apps Script, and how we can use it to achieve this as using PHP API wasn't a requirement.

Using Google Apps Script we can clear the content of the Google Spreadsheet daily or on specific time of the day.

1) Open the spreadsheet and click Tools > Script Editor.

2) Copy and Paste the following Google Apps Script

function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet(); // gets opened spreadsheet
var menuEntries = [ {name: "Clear", functionName: "clear"} ]; //adds menu
ss.addMenu("Script", menuEntries); //adds submenu 'Script'
function clear() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheets(); // get all sheets
ss[0].clear();  //we can set which sheet to clear

Save and give relevant name to the script.

3) Set Trigger to execute the 'clear' function at midnight

Triggers > Current Scripts Trigger > Add New

This script also adds a new menu to toolbar, Scripts > Clear

We can set different type of triggers, for more read script guide.


P.S. Tad, Enjoy!