Skip to content

Instantly share code, notes, and snippets.

@pozhidaevak
Last active May 24, 2018 13:36
Show Gist options
  • Save pozhidaevak/facb47e14e73290f2cd853771d25c984 to your computer and use it in GitHub Desktop.
Save pozhidaevak/facb47e14e73290f2cd853771d25c984 to your computer and use it in GitHub Desktop.
Google sheets: fast creation of URL from cell by template
// Just change 22nd string to your template :-D
// This script adds "URL" menu to google sheet with one intem "create URL".
// You need select cell range and click on the menu item in order to make links from your cells.
// It can create links by template 123 => https://example.com/browse/123/.
var ss = SpreadsheetApp.getActiveSpreadsheet();
function onOpen() {
var menu = [{name: "create URL", functionName: "createURL"}];
ss.addMenu("URL", menu);
}
function createURL() {
var aRange = ss.getActiveRange()
var numRows = aRange.getNumRows();
var numCols = aRange.getNumColumns();
for (var i = 1; i <= numRows; i++) {
for (var j = 1; j <= numCols; j++) {
var currentValue = aRange.getCell(i,j).getValue();
//String with template
aRange.getCell(i,j).setValue('=HYPERLINK("https://example.com/browse/'+currentValue+'","'+currentValue+'")');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment