Skip to content

Instantly share code, notes, and snippets.

@anthonybudd
Forked from oshliaer/.md
Last active January 4, 2017 15:20
Show Gist options
  • Save anthonybudd/ea97cf89798396c658fc7583a0a13101 to your computer and use it in GitHub Desktop.
Save anthonybudd/ea97cf89798396c658fc7583a0a13101 to your computer and use it in GitHub Desktop.
Select several elements #gas #sheets
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment