Google Apps Spreadsheet open specific sheet based on current date (Month) -
i creating spreadsheet in google apps used log client attendance. spreadsheet contains 12 sheets. each sheet represents month of year sheet 1 represents january, sheet 2 represents february etc.
i trying create google apps script using on_open function automatically open relevant sheet based on current date.
for example if current date 18/02/2013 spreadsheet automatically open sheet 2 (february) in focus.
i think correct in using spreadsheetapp.setactivesheet don't know how capture date month google app script.
i assuming script flow bit following?
if date = 18/02/2013 spreadsheetapp.setactivesheet 2
any gratefully received.
to month number, 0 - 11:
var month = (new date()).getmonth();
assuming have { sheet1
.. sheet12
} representing january - december, work:
/** * selects monthly sheet */ function onopen() { var month = (new date()).getmonth(); var ss = spreadsheetapp.getactivespreadsheet(); var sheet = ss.getsheets()[month]; ss.setactivesheet(sheet); };
alternatively, name sheets month, , find appropriate monthly sheet name. allow have other non-monthly sheets in spreadsheet:
/** * selects monthly sheet */ function onopen() { var monthtabs = [ "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december" ]; var month = (new date()).getmonth(); var ss = spreadsheetapp.getactivespreadsheet(); var sheet = ss.getsheetbyname(monthtabs[month]); ss.setactivesheet(sheet); };