Reputation: 6737
I'm working on the very early stages of a video game economy tracker to eventually implement better economy dynamics into future MMORPGs. So, first I am trying to create a Google spreadsheet to keep track of the prices, here's the relevant snippet of code in Google Scripts. As far as I can tell, Google Scripts uses the exact same functionality as JavaScript.
function makeLink(item) {
var encodedItem = encodeURI(underScore(toTitleCase(item)));
//make spaces into underscores, then URL-encode the rest
var wiki = "http://wiki.videogame_address.org/";
//the base wiki URL for the video game
wikiLink = wiki+encodedItem;
//link to the item in the wiki
var href = "=HYPERLINK(\""+wikiLink+"\",\""+toTitleCase(item)+"\")";
//attempting to have Google Spreadsheet make a URL
//yields =HYPERLINK("http://wiki.videgame.org/Giant_Head","Giant Head")
return href;
};
The resulting href variable only gives the text output
=HYPERLINK("http://wiki.videgame.org/Giant_Head","Giant Head")
This is the exact correct syntax for the spreadsheet to create a link, however, it just leaves it as text. Is there a way to force Google to digest the text that is output here instead of leaving it as text?
Upvotes: 1
Views: 4132
Reputation: 215
Check this out..
http://code.google.com/p/google-apps-script-issues/issues/detail?id=1592
It appears that this feature is not available and will not be available. :(
If you are willing to skip on the text-display 'Giant Head', you can at least return link for a working link.
function makeLink(item) {
var encodedItem = encodeURI(underScore(toTitleCase(item)));
var wiki = "http://wiki.videogame_address.org/";
wikiLink = wiki+encodedItem;
return wikiLink;
};
Upvotes: 0
Reputation: 50905
Use the setFormula
method:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets().shift();
var cell = sheet.setActiveCell("B5");
var newLink = makeLink("whatever");
cell.setFormula(newLink);
References:
Upvotes: 3