如何制作根据单元格值变化的超链接功能?

How to make a hyperlink function that changes according to cell value?

我想在单元格中输入一个值并获得一个研究 hyperlink。

我正在使用 link:https://projudi.tjpr.jus.br/projudi/processo/buscaProcesso.do?actionType=pesquisaSimples&flagNumeroUnico=true&numeroProcesso=

例如,我在空白单元格中写入一个值 (00156610320218160021),然后 link 将是:

=HYPERLINK("https://projudi.tjpr.jus.br/projudi/processo/buscaProcesso.do?actionType=pesquisaSimples&flagNumeroUnico=true&numeroProcesso=0015661-03.2021.8.16.0021";"0015661-03.2021.8.16.0021")

下一个单元格,如果我写这个值(0012204-19.2019.8.16.0025),link将是:=HYPERLINK("https://projudi.tjpr.jus.br/projudi/processo/buscaProcesso.do?actionType=pesquisaSimples&flagNumeroUnico=true&numeroProcesso=0012204-19.2019.8.16.0025";"0012204-19.2019.8.16.0025")

重要事项:

  1. 在我写这个数字之前,单元格需要留空;

  2. hyperlink 需要根据单元格的值进行更改;

基本上我想在 A 列的每个单元格中输入一个值,并得到这些不同的 links。

有人知道我该怎么做吗?

描述

您可以简单地在下一个单元格中添加公式并连接单元格 A 列的内容。另一种选择是使用 onEdit(e) 简单触发器来替换 B 列的内容。

公式

=HYPERLINK("https://projudi.tjpr.jus.br/projudi/processo/buscaProcesso.do?actionType=pesquisaSimples&flagNumeroUnico=true&numeroProcesso="&A1&";"&A1)

脚本

function onEdit(e) {
  if( e.range.getSheet().getName() === "Sheet1" ) { // Make sure we are on the right sheet
    if( e.range.getColumn() === 1 ) {  // Make sure the edit occured in column A
      var link = "https://projudi.tjpr.jus.br/projudi/processo/buscaProcesso.do?actionType=pesquisaSimples&flagNumeroUnico=true&numeroProcesso=";
      link = link.concat(e.value,";",e.value);
      e.range.offset(0,1).setValue(link);
    }
  }
}

参考

这是另一个 Apps 脚本解决方案,当您对 A 列进行更改时,它将在第 B 列的每一行生成链接。如果您还需要在 A 列上粘贴大量 ID 并希望一次生成它们,这可能会很有用。

function onEdit(e) {

  var editedrange = e.range; //gets the range that triggered the edit event

  if (editedrange.getColumn() == 1) {//only works if the change occurs on the first column
      var colvalue
      var nextcell
      var url

    for(var i = 1; i<=editedrange.getNumRows(); i++){ //iterates through all the edited rows in the first column
      colvalue = editedrange.getCell(i,1).getValue(); //gets value of the cell at row i of column 1
      nextcell = editedrange.getCell(i,1).offset(0, 1) // gets the cell in the next column

      url = `https://projudi.tjpr.jus.br/projudi/processo/buscaProcesso.do?actionType=pesquisaSimples&flagNumeroUnico=true&numeroProcesso=${colvalue}` //builds the URL
      nextcell.setFormula(`=HYPERLINK("${url}","${colvalue}")`) //sets the URL in a formula on the next cell
    }
  }
}

我通过这种方式解决了部分问题:

function hyperlink(){
  var activeSheet = SpreadsheetApp.getActiveSheet();
  var a1 = activeSheet.getSelection().getActiveRange().getA1Notation();
  //var a1 = activeSheet.getActiveCell().getA1Notation();
  var values = activeSheet.getRange(a1).getValues();
  const link = "https://projudi.tjpr.jus.br/projudi/processo/buscaProcesso.do?actionType=pesquisaSimples&flagNumeroUnico=true&numeroProcesso="
  var hyperVal= values.map(row=> row.map(col=> `=HYPERLINK("${link}${col}";"${col}")` ));
  activeSheet.getRange(a1).setValues(hyperVal);
  activeSheet.getRange(a1).setShowHyperlink(true); /* I initially just tried doing this, but without setting the HYPERLINK formula, it did nothing */
}

该解决方案适用于选中单元格的情况。

我想在单元格中写入值并自动看到 link。不幸的是,我找不到解决方案。