【问题标题】:Google Scripts won't return hyperlinks in Google SpreadsheetGoogle 脚本不会在 Google 电子表格中返回超链接
【发布时间】:2013-04-13 02:03:19
【问题描述】:

我正在开发视频游戏经济跟踪器的早期阶段,以最终在未来的 MMORPG 中实现更好的经济动态。因此,首先我尝试创建一个 Google 电子表格来跟踪价格,这是 Google Scripts 中相关的 sn-p 代码。据我所知,Google Scripts 使用与 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;
};

生成的 href 变量只给出文本输出

=HYPERLINK("http://wiki.videgame.org/Giant_Head","Giant Head")

这是电子表格创建链接的正确语法,但是,它只是将其保留为文本。有没有办法强制 Google 消化此处输出的文本,而不是将其保留为文本?

【问题讨论】:

标签: javascript google-apps-script google-sheets


【解决方案1】:

使用setFormula 方法:

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets().shift();
var cell = sheet.setActiveCell("B5");
var newLink = makeLink("whatever");
cell.setFormula(newLink);

参考资料:

【讨论】:

    【解决方案2】:

    看看这个..
    http://code.google.com/p/google-apps-script-issues/issues/detail?id=1592

    此功能似乎不可用,也将不可用。 :(

    如果您愿意跳过文本显示“巨头”,您至少可以返回链接以获得工作链接。

    function makeLink(item) {
      var encodedItem = encodeURI(underScore(toTitleCase(item)));
      var wiki = "http://wiki.videogame_address.org/"; 
      wikiLink = wiki+encodedItem;     
      return wikiLink;
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多