Created
August 4, 2015 16:45
-
-
Save bennettscience/5629c536e82661a419b6 to your computer and use it in GitHub Desktop.
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
// Grabbed from http://webapps.stackexchange.com/questions/76050/google-sheets-function-to-get-a-shortened-url-from-bit-ly-or-goo-gl-etc | |
// Add a menu action item when the sheet is opened. | |
function onOpen() { | |
SpreadsheetApp.getUi() | |
.createMenu("Shorten") | |
.addItem("Go !!","rangeShort") | |
.addToUi() | |
} | |
// Get the active range. Can be a single cell or a highlighted column. | |
function rangeShort() { | |
var range = SpreadsheetApp.getActiveRange(), data = range.getValues(); | |
var output = []; | |
for(var i = 0, iLen = data.length; i < iLen; i++) { | |
var url = UrlShortener.Url.insert({longUrl: data[i][0]}); | |
output.push([url.id]); | |
} | |
// Add the shortened URL to the cell immediately to the right of the selected cell. | |
// If you want to replace the selected URL rather than append, change range.offset to (0,0) | |
range.offset(0,1).setValues(output); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment