我使用Google脚本制作了许多电子表格的副本,其中嵌入了代码。我希望能够记录每个电子表格副本的脚本ID,而不必手动进入每个电子表格,然后是脚本文件,然后复制脚本ID。我知道,在脚本中,我可以使用ScriptApp.getScriptId(),但这当然不能从独立的脚本中引用文件的副本。
tl;dr:如果我在Google中嵌入了一个脚本,并且我有Google的文件ID,我可以使用Apps脚本编程访问脚本ID吗?
发布于 2022-05-22 10:31:04
也许你可以做以下几件事,试一试:
步骤1:您需要在每个脚本中插入以下函数:
function MyScriptID(){return ScriptApp.getScriptId()}步骤2:使用单独的电子表格操作数据(一种母版表),您将运行以下函数:
function FindScriptID() {
// Insert the ID of the sheet you want to retrieve the script Id from
var sheet = SpreadsheetApp.openByUrl('your ID')
// name the sheet where you want to insert the formula
var destination = sheet.getSheetByName("mysheet");
// Choose a cell to insert the formula - example: (4,2)
destination.getRange(4, 2).setFormula('=MyScriptID()');
SpreadsheetApp.flush();
// get the displayed ID from the formula, which is actually the ID of the attached script
var myscriptID = destination.getRange(4, 2).getDisplayValue();
Logger.log(myscriptID)
// You can now write the ID of your script within the sheet you've ran the above function, choose a sheet where you wan to write the ID - e.g. Sheet1
var currentsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
//Choose a cell to write the link of you your script or just the ID
currentsheet.getRange(2, 2).setValue('https://script.google.com/a/ais.sch.sa/d/' + myscriptID + '/edit')
}如果您需要使用许多电子表格来迭代,那么现在可以改进这个母版表,尽管所有这些都可以一次完成:
在总表内:
function MyScriptID(){return ScriptApp.getScriptId()})顶部,您迭代了所有电子表格链接以插入公式H 211H 112您将检索到的脚本in或链接H 213F 214写入主表有时,显示的值会出现一些错误,如('Loading...')
https://stackoverflow.com/questions/71106234
复制相似问题