-
-
Save labnol/1907312 to your computer and use it in GitHub Desktop.
Google Apps Script to turn Twitter usernames into links
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
function makeLinks() { | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
var twitterDataRange = ss.getRangeByName("Twitter3"); | |
vals = twitterDataRange.getValues(); | |
for (i in vals) { | |
var row = vals[i]; | |
for (j in row) { | |
var col = vals[i][j]; | |
vals[i][j] = makeLink(col); | |
} | |
} | |
twitterDataRange.setFormulas(vals); | |
} | |
function makeLink(cellContent) { | |
if (cellContent[0] == '@') { | |
var url = "http://twitter.com/" + cellContent.substr(1); | |
var newContent = "=HYPERLINK(\"" + url+ "\",\"" + cellContent + "\")"; | |
return newContent; | |
} else { | |
return cellContent; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment