如何检索工作表名称列表并在更改时自动更新? [英] How can I retrieve a list of Sheet Names and auto-update on change?
本文介绍了如何检索工作表名称列表并在更改时自动更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个很简单的问题:
I have a quite simple problem:
我正在尝试检索文档中存在的所有图纸的名称,但是问题是它不会根据更改自动更新.我已经尝试过在我的内部使用GoogleClock()函数,并且将触发器设置为时间驱动和事件驱动,但是它们都不适合我,我必须重写自定义函数以刷新数据,但是它不能解决任何问题.
I'm trying retrieve the name of all the Sheets present in my document, but the problem is that it doesn't auto-updates on change. I've already tried using the GoogleClock() function inside mine, and I set the triggers either as time driven, and event driven but neither of them works for me, I have to rewrite my custom function in order to refresh the data, but it doesn't solves any problem.
function sheetNames() {
var out = new Array()
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
for (var i=0 ; i<sheets.length ; i++) out.push( [ sheets[i].getName() ] )
return out
}
我会爱3000个可以帮助我的人.最好的问候!
I'll love 3000 anyone who can help me. Best Regards!
P.D.我是一个javascript假人
P.D. I am a javascript dummy
推荐答案
脚本逻辑:
- 除非参数更改,否则自定义函数不会更新.
- 创建一个onChange触发器,以使用textFinder更改电子表格中所有自定义函数的所有参数
/*@customfunction*/
function sheetNames(e) {
return SpreadsheetApp.getActive()
.getSheets()
.map(function(sheet) {
return sheet.getName();
});
}
/*Create a installable trigger to listen to grid changes on the sheet*/
function onChange(e) {
if (!/GRID/.test(e.changeType)) return; //Listen only to grid change
SpreadsheetApp.getActive()
.createTextFinder('=SHEETNAMES\\([^)]*\\)')
.matchFormulaText(true)
.matchCase(false)
.useRegularExpression(true)
.replaceAllWith(
'=SHEETNAMES(' + (Math.floor(Math.random() * 500) + 1) + ')'
);
}
阅读:
- 可安装的触发器
- TextFinder
- Installable triggers
- TextFinder
To Read:
这篇关于如何检索工作表名称列表并在更改时自动更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文