google spreadsheet - Iterate through range and match values -
i have spreadsheet 2 sheets: week#, events.
sheet "week#" (calendar week # in column , start day of week in column b):
01 january 4, 2016
02 january 11, 2016
03 january 18, 2016
04 january 25, 2016
05 february 1, 2016
and on till week 52
sheet "events" has next columns:
facility, repeats, belongs week #, week # starts on, item, action, status.
it's filled (number of rows varies):
salona, monthly, 4, january 25,2016, floor, mop floor, created
the script this:
function createeventmanually (title, date) { var sheet = spreadsheetapp.getactivesheet(); var row = sheet.getactiverange().getrowindex(); var eventstatus = sheet.getrange(row, 7).setvalue("created"); var title = sheet.getrange(row,1).getvalue()+" "+"week "+sheet.getrange(row,3).getvalue()+" "+sheet.getrange(row,5).getvalue()+":"+" "+sheet.getrange(row,6).getvalue(); var cal = calendarapp.getcalendarsbyname('rm') [0]; var date = sheet.getrange(row,4).getvalue(); var event = cal.createalldayevent(title, date); }
i manually copy , paste calendar dates sheet week# column "week # starts on" in sheet events. , run script every time create event. how automatize process? understand done through iteration cannot figure out. thank in advance.
if want 52 calendar events (one every week) every different task in events sheet, code how need it.
function createalleventsfortheyear() { var allrowsofdataineventsheet,alldatainweeksheet,cal,eventsh,i,j,l,lj,lastrowineventsheet,lastrowinweeksheet, lastcolumnineventsheet,lastcolinweeksh,ss,row, weeknumbersheet,rowdatabeingprocessedfromeventssheet,thiseventtitle,thisweeksdate; cal = calendarapp.getcalendarsbyname('rm')[0]; ss = spreadsheetapp.getactivespreadsheet(); eventsh = ss.getsheetbyname('events'); weeknumbersheet = ss.getsheetbyname('week#'); lastrowineventsheet = eventsh.getlastrow(); lastrowinweeksheet = weeknumbersheet.getlastrow(); lastcolumnineventsheet = eventsh.getlastcolumn(); lastcolinweeksh = weeknumbersheet.getlastcolumn(); allrowsofdataineventsheet = eventsh.getrange(2, 1, lastrowineventsheet-1, lastcolumnineventsheet).getvalues(); alldatainweeksheet = weeknumbersheet.getrange(2, 1, lastcolinweeksh-1, lastcolinweeksh).getvalues(); l = allrowsofdataineventsheet.length; lj = alldatainweeksheet.length; (i=0;i<l;i+=1) { //loop through every row of data in events sheet rowdatabeingprocessedfromeventssheet = allrowsofdataineventsheet[i];//get 1 row of data thiseventtitle = rowdatabeingprocessedfromeventssheet[0] + "week" + rowdatabeingprocessedfromeventssheet[2] + " " + rowdatabeingprocessedfromeventssheet[4] + ": " + rowdatabeingprocessedfromeventssheet[5]; (j=0;j<lj;j+=1) {//for every row in events sheet, create event every week of year. 52 events event type thisweeksdate = alldatainweeksheet[j][1];//get date second column of data in weeks# sheet cal.createalldayevent(thiseventtitle, thisweeksdate); }; eventsh.getrange(i+2, 7).setvalue("created");//i starts @ 0, data starts on row 2 }; };
i have not tested this, or debugged it, may not run perfectly.
Comments
Post a Comment