English 中文(简体)
自定义 Google 电子表格 函数返回超链接或现有公式
原标题:Custom Google Spreadsheet Function Returning a Hyperlink or an Existing Formula

我目前在谷歌电子表格中输入超链接,

=HYPERLINK("http://jira.com/browse/ISSUE-12345","ISSUE-12345")

我每次重复“ ISSSU- 12345 ” 。 我想创建一个函数 JIRA( 12345), 与上面的超链接结果相同 。 是否有一种方法可以将超链接返回到脚本中, 类似

function JIRA(jiraNum) {
  // Returns JIRA hyperlink
  var link = ("http://jira.com/browse/ISSUE-"+jiraNum,"ISSUE-"+jiraNum);
  return link;
}

会有用吗?

问题回答

您可以通过设定以下单元格值来减轻 set Forumla 的需要,并且必须处理权限问题:

=HYPERLINK(getJiraTicketLink(12345), getJiraTicketLabel(12345))

此处 12345 当然可以是 (隐藏列-) 相邻单元格, 而不是硬编码字符串 。

然后您创建两个简单函数, 类似以下函数 :

var JIRA_BASE_URL = "http://jira.com/";
var JIRA_PROJECT_PREFIX = "ISSUE-";

function getJiraTicketLink(jiraNum) {
  return JIRA_BASE_URL + "browse/" + JIRA_PROJECT_PREFIX + jiraNum;
}

function getJiraTicketLabel(jiraNum) {
  return JIRA_PROJECT_PREFIX + jiraNum;
}

我同样挣扎着, 提出", https://code.google.com/p/google-apps-stative-issues/issues/detail?id=2521" rel="nofol", 并收到一个有趣的解决方案 :

适用于你的情况,下列措施将有效。

function onEdit(e) {
 // limit to only apply to specific range
  col = e.range.getColumn();
  row = e.range.getRow();        
  if (row > 1 && row < 10 && col == 1) { // A2:A9
    if (e.value != "")
      e.range.setFormula("=HYPERLINK("http://jira.com/browse/ISSUE-"+e.value+"", "ISSUE-"+e.value+"")");
  }
}

我认为这是一种变通办法,但目前可能是唯一的办法。

查看此 : < a href=" "https://code.google.com/p/google-apps-stative-issues/issues/ detail? id=2521" rel="nofollow" >https://code.google.com/p/google-apps-static-issues/issues/detail?id=2521

似乎没有这种特征,也不可能有这种特征。

如果您愿意跳过文本播放的 SISUE-1234, 您至少可以返回工作链接的“ 坚固” 链接 < / 坚固 ” 。

function JIRA(jiraNum) {
  var link =  http://jira.com/browse/ISSUE-  + jiraNum;
  return link;
 }

我希望这有帮助

您可以使用丰富的文本构建器 :

function onEdit(e){
      var jiraIDColumnID = 1;
      var jiraIDfirstRow = 5;
      var jiraBaseURL = "https://jira.tttttt.com/";
      if (e.value != null && 
          e.value.trim().length != 0 &&
          e.range.getColumn() == jiraIDColumnID && 
          e.range.getRow() >= jiraIDfirstRow ) 
      {
        var richValue = SpreadsheetApp.newRichTextValue()
          .setText(e.value)
          .setLinkUrl(jiraBaseURL + "browse/" + e.value)
          .build();
        e.range.setRichTextValue(richValue);
      } 
    }




相关问题
How to use year counter google app script?

I need an urgent help i have data as follows in a google sheet i need to add a year counter to the column d as follows using google apps script

Google Spreadsheet multiple column filter using OR

I have a Google Spreadsheet with 3 columns that are either blank or have a value. I want to get the count of the number of rows that has A and either B or C populated. If I were writing a SQL query ...

Run Google Apps Script on Google-Spreadsheet event?

If I create a Google apps script, can I hook it up to Google spreadsheet to run based on an event, or must I manually invoke it? I don t know if Google Sheets supports any events. For example: a ...

How do I insert a row in to a Google spreadsheet using c#

I ve seen; Accessing Google Spreadsheets with C# using Google Data API and http://code.google.com/apis/spreadsheets/data/2.0/developers_guide_dotnet.html#CreatingRows However i m still having ...

using Zend_Gdata_Spreadsheets for public spreadsheets?

I have this code which is working, to load a Google Spreadsheet and load some data from it. If the spreadsheet in question is public, how do i modify the code to not require a username/password? $key=...

Programatically updating a Google spreadsheet

I ve got a pre-existing Google spreadsheet. Each month I update this document. I ve got a template workseet in the spreadseet that I d like to clone and then update. I d prefer to clone the ...

热门标签