要求是我必须在工作表中创建一个包含许多工作表的索引,因此从索引表中我可以直接导航到目标。
我写了以下脚本
// 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 :(得分:2)
添加超链接:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var cell = sheet.getRange("B5");
cell.setFormula('=HYPERLINK("http://www.google.com/","Google")');
答案 1 :(得分: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
+'")'])