2017-07-14 93 views
1

要求是我必须在有很多工作表的工作表中创建索引,因此从索引表我可以直接导航到目标。将文本添加到Google电子表格中作为超链接

我写了下面的脚本

// custom menu function 
 
function onOpen() { 
 
    var ui = SpreadsheetApp.getUi(); 
 
    ui.addItem('toTablrOfContent','toTablrOfContent') 
 
     .addToUi(); 
 
    
 
} 
 

 
// function to write selected cell data to index sheet 
 
function toTablrOfContent() { 
 
    
 
var selectdCellData = SpreadsheetApp.getActiveSpreadsheet().getActiveCell().getValue(); 
 
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[11]; // 11 is the index sheet 
 
sheet.appendRow([selectdCellData]); 
 

该脚本将所选单元格的数据发送到的“指标”表 最后一排,但我不能够插入这是一个超链接到选定的单元格。这可以做到吗?

回答

0
// 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 
    +'")']) 
2

添加一个超链接:

var ss = SpreadsheetApp.getActiveSpreadsheet(); 
 
var sheet = ss.getSheets()[0]; 
 

 
var cell = sheet.getRange("B5"); 
 
cell.setFormula('=HYPERLINK("http://www.google.com/","Google")');

+0

感谢@OblongMedulla:我的要求是有点不同,在这里我想创建链接到同一工作表单元格的一些,不一些URL。但它仍然有帮助。 –

相关问题