###Select several elements
https://docs.google.com/spreadsheets/d/1H7y_Aoy6pKHUhvXo6EwiYuNKl-7oe9Zyl7mN3QYRIPk/edit?usp=sharing Copy the project here http://goo.gl/LxGXfU Disscussion http://goo.gl/UWi1ee http://www.youtube.com/watch?v=dm4z9l26O0I
###Select several elements
https://docs.google.com/spreadsheets/d/1H7y_Aoy6pKHUhvXo6EwiYuNKl-7oe9Zyl7mN3QYRIPk/edit?usp=sharing Copy the project here http://goo.gl/LxGXfU Disscussion http://goo.gl/UWi1ee http://www.youtube.com/watch?v=dm4z9l26O0I
function onOpen(e) { | |
SpreadsheetApp.getUi() | |
.createMenu('Subjects') | |
.addItem('Select Subjects', 'showDialog') | |
.addToUi(); | |
} | |
function showDialog() { | |
var html = HtmlService.createTemplateFromFile('Page').evaluate(); | |
SpreadsheetApp.getUi() | |
.showSidebar(html); | |
} | |
var valid = function(){ | |
try{ | |
return SpreadsheetApp.getActiveRange().getDataValidation().getCriteriaValues()[0].getValues(); | |
}catch(e){ | |
return null | |
} | |
} | |
function fillCell(e){ | |
var s = []; | |
for(var i in e){ | |
if(i.substr(0, 2) == 'ch') s.push(e[i]); | |
} | |
if(s.length) SpreadsheetApp.getActiveRange().setValue(s.join(', ')); | |
} |
<div> | |
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css"> | |
<? var data = valid(); ?> | |
<div class="sidebar branding-below"> | |
<div class="block form-group"> | |
<form id="form" name="form"> | |
<? if(Object.prototype.toString.call(data) === '[object Array]') { ?> | |
<? for (var i = 0; i < data.length; i++) { ?> | |
<? for (var j = 0; j < data[i].length; j++) { ?> | |
<? if(data[i][j] != ''){ ?> | |
<input type="checkbox" id="ch<?= '' + i + j ?>" name="ch<?= '' + i + j ?>" value="<?= data[i][j] ?>"><?= data[i][j] ?><br> | |
<? } ?> | |
<? } ?> | |
<? } ?> | |
<input type="button" class="action" value="Set Subjects" onclick="google.script.run.fillCell(this.parentNode)" /> | |
<? } else { ?> | |
<p>May be current cell havn't the <a href="https://support.google.com/drive/answer/139705?hl=en">Data validation...</a></p> | |
<? } ?> | |
</form> | |
</div> | |
</div> | |
</div> |