Created
March 27, 2018 13:13
-
-
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
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
// 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