Skip to content

Instantly share code, notes, and snippets.

@goelp
Created March 27, 2018 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goelp/773050e13d69699e8144957b3df06e16 to your computer and use it in GitHub Desktop.
Save goelp/773050e13d69699e8144957b3df06e16 to your computer and use it in GitHub Desktop.
Google Apps Script functions to pick a range and populate in text field in sidebar
// Add the options to the custom menu
function onOpen() {
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.createMenu('Custom Menu')
.addItem('Show Settings', 'showSidebar')
.addToUi();
}
// initiates the sidebar
function showSidebar() {
var html = HtmlService.createHtmlOutputFromFile('settings')
.setTitle('Settings Sidebar')
.setWidth(300);
SpreadsheetApp.getUi().showSidebar(html);
}
/** Function to pick the selected range from the Google Sheet
* This returns the picked range, so that the client-side JS
* function (in HTML file) can populate it in the text field **/
function getSelectedRange(){
var selected = SpreadsheetApp.getActiveSheet().getActiveRange(); // Gets the selected range
var rangeString = selected.getA1Notation(); // converts it to the A1 type notation
return rangeString;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment