Created
May 7, 2024 10:51
-
-
Save LouDnl/5e3c8843e1dd4a021fa006bca1499aa3 to your computer and use it in GitHub Desktop.
Sheets siderbar script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Changes the variable validation if needed | |
*/ | |
var validation = { | |
sheet: 'Variabelen', | |
range: 'E2:E12' | |
} | |
// Simple trigger for the onInstall event | |
function onInstall(e) { | |
Keep.info('installed the addon'); | |
setProperties();/** | |
* Changes the variable validation if needed | |
*/ | |
var validation = { | |
sheet: 'Variabelen', | |
range: 'E2:E12' | |
} | |
// Simple trigger for the onInstall event | |
function onInstall(e) { | |
Keep.info('installed the addon'); | |
setProperties(); | |
createTriggers(); | |
initialize(e); | |
} | |
// Create installable triggers for onOpen and onEdit | |
function createTriggers() { | |
ScriptApp.newTrigger('initialize') | |
.forSpreadsheet(spreadsheet) | |
.onOpen() | |
.create(); | |
ScriptApp.newTrigger('selectAction') | |
.forSpreadsheet(spreadsheet) | |
.onEdit() | |
.create(); | |
} | |
/** | |
* Creates a menu entry in the Google Docs UI when the document is opened. | |
* | |
* @param {object} e The event parameter for a simple onOpen trigger. To | |
* determine which authorization mode (ScriptApp.AuthMode) the trigger is | |
* running in, inspect e.authMode. | |
*/ | |
// function onOpen(e) { | |
function selectAction(e) { | |
SpreadsheetApp.getUi().createMenu('Sidebar') | |
.addItem('Show Sidebar', 'showSidebar') | |
.addToUi(); | |
showSidebar(); | |
} | |
/** | |
* Opens a sidebar in the document containing the add-on's user interface. | |
*/ | |
function showSidebar() { | |
SpreadsheetApp.getUi() | |
.showSidebar(HtmlService.createTemplateFromFile('SIDEBAR') | |
.evaluate() | |
.setSandboxMode(HtmlService.SandboxMode.IFRAME) | |
.setTitle('Multiple selector')); | |
} | |
function getOptions() { | |
return SpreadsheetApp.getActive().getSheetByName(validation.sheet).getRange(validation.range).getDisplayValues() | |
.filter(String) | |
.reduce(function(a, b) { | |
return a.concat(b) | |
}) | |
} | |
function process(arr) { | |
arr.length > 0 ? SpreadsheetApp.getActiveRange().clearContent().setValue(arr.join(", ")) : | |
SpreadsheetApp.getUi().alert('No options selected') | |
} | |
createTriggers(); | |
initialize(e); | |
} | |
// Create installable triggers for onOpen and onEdit | |
function createTriggers() { | |
ScriptApp.newTrigger('initialize') | |
.forSpreadsheet(spreadsheet) | |
.onOpen() | |
.create(); | |
ScriptApp.newTrigger('selectAction') | |
.forSpreadsheet(spreadsheet) | |
.onEdit() | |
.create(); | |
} | |
/** | |
* Creates a menu entry in the Google Docs UI when the document is opened. | |
* | |
* @param {object} e The event parameter for a simple onOpen trigger. To | |
* determine which authorization mode (ScriptApp.AuthMode) the trigger is | |
* running in, inspect e.authMode. | |
*/ | |
// function onOpen(e) { | |
function selectAction(e) { | |
SpreadsheetApp.getUi().createMenu('Sidebar') | |
.addItem('Show Sidebar', 'showSidebar') | |
.addToUi(); | |
showSidebar(); | |
} | |
/** | |
* Opens a sidebar in the document containing the add-on's user interface. | |
*/ | |
function showSidebar() { | |
SpreadsheetApp.getUi() | |
.showSidebar(HtmlService.createTemplateFromFile('SIDEBAR') | |
.evaluate() | |
.setSandboxMode(HtmlService.SandboxMode.IFRAME) | |
.setTitle('Multiple selector')); | |
} | |
function getOptions() { | |
return SpreadsheetApp.getActive().getSheetByName(validation.sheet).getRange(validation.range).getDisplayValues() | |
.filter(String) | |
.reduce(function(a, b) { | |
return a.concat(b) | |
}) | |
} | |
function process(arr) { | |
arr.length > 0 ? SpreadsheetApp.getActiveRange().clearContent().setValue(arr.join(", ")) : | |
SpreadsheetApp.getUi().alert('No options selected') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment