Google apps script 将文本作为超链接添加到google电子表格

Google apps script 将文本作为超链接添加到google电子表格,google-apps-script,Google Apps Script,要求是我必须在一个有很多工作表的工作表中创建一个索引,这样我就可以从索引表直接导航到目标 我写了以下脚本 //自定义菜单函数 函数onOpen(){ var ui=SpreadsheetApp.getUi(); ui.addItem('toTablrOfContent','toTablrOfContent') .addToUi(); } //函数将所选单元格数据写入索引表 函数totablorofcontent(){ var selectdCellData=SpreadsheetApp.get

要求是我必须在一个有很多工作表的工作表中创建一个索引,这样我就可以从索引表直接导航到目标

我写了以下脚本

//自定义菜单函数
函数onOpen(){
var ui=SpreadsheetApp.getUi();
ui.addItem('toTablrOfContent','toTablrOfContent')
.addToUi();
}
//函数将所选单元格数据写入索引表
函数totablorofcontent(){
var selectdCellData=SpreadsheetApp.getActiveSpreadsheet().getActiveCell().getValue();
var sheet=SpreadsheetApp.getActiveSpreadsheet().getSheets()[11];//11是索引表
sheet.appendRow([selectdCellData]);
要添加超链接:

var ss=SpreadsheetApp.getActiveSpreadsheet();
var sheet=ss.getSheets()[0];
var单元格=表。getRange(“B5”);

cell.setFormula('=超链接(“http://www.google.com/“,”谷歌“)”;
谢谢@oblongmylma:我的要求有点不同,我试图创建指向同一工作表中某个单元格的链接,而不是指向某个URL的链接。但仍然有帮助。
// custom menu function
function onOpen() {
   var ui = SpreadsheetApp.getUi();
  ui.createMenu('Custom Menu')
      .addItem('toTablrOfContent','toTablrOfContent')
      .addToUi();
}



// function to write selected cell data to index sheet
function toTablrOfContent() {

 var selectdCellData = SpreadsheetApp.getActiveSpreadsheet().getActiveCell().getValue();

// selected data to be sent to 11th sheet
 var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[11]; 

//I am entring this to 5th column
  sheet.appendRow(['','','','','=HYPERLINK("#gid=' + SpreadsheetApp.getActiveSpreadsheet().getActiveCell().getGridId()
  + '&range=' 
  +SpreadsheetApp.getActiveSpreadsheet().getActiveCell().getA1Notation()
  +'","'
  + selectdCellData
    +'")'])