دنبال کننده ها

۱۳۹۶ اسفند ۱۰, پنجشنبه

Javascript coding for Google Sheets and Google Forms

[ad_1]



I would be most grateful if someone could explain line by line what the following pieces of codes do. There are general overviews of what the codes below do, but I need a line by line explanation to understand what is going on. Thank you.



Code snippet 1



/**
* Creates a Google Form that allows respondents to select which conference
* sessions they would like to attend, grouped by date and start time.
*
* @param Spreadsheet ss The spreadsheet that contains the conference data.
* @param String[][] values Cell values for the spreadsheet range.
*/
function setUpForm_(ss, values)
// Group the sessions by date and time so that they can be passed to the
form.
var schedule = ;
for (var i = 1; i < values.length; i++)
var session = values[i];
var day = session[1].toLocaleDateString();
var time = session[2].toLocaleTimeString();
if (!schedule[day])
schedule[day] = ;

if (!schedule[day][time])
schedule[day][time] = [];

schedule[day][time].push(session[0]);



Code snippet 2



// Create the form and add a multiple-choice question for each timeslot.
var form = FormApp.create('Conference Form');
form.setDestination(FormApp.DestinationType.SPREADSHEET, ss.getId());
form.addTextItem().setTitle('Name').setRequired(true);
form.addTextItem().setTitle('Email').setRequired(true);
for (var day in schedule)
var header = form.addSectionHeaderItem().setTitle('Sessions for ' + day);
for (var time in schedule[day])
var item = form.addMultipleChoiceItem().setTitle(time + ' ' + day)
.setChoiceValues(schedule[day][time]);






[ad_2]

لینک منبع