列出Google表格中的图表名称并跳过前两个 [英] List names of sheets in Google Sheets and skip the first two

查看:88
本文介绍了列出Google表格中的图表名称并跳过前两个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了代码来列出Google表格中所有工作表的名称(来自此处 ):
$ b $ pre $ 函数SheetNames(){//用作自定义函数:= SheetNames(GoogleClock())
尝试{
var sheets = SpreadsheetApp.getActiveSpreadsheet()。getSheets()
var out = new Array(sheets.length + 1);
// out [0] = [Name,gid];
for(var i = 1; i< sheets.length + 1; i ++)out [i] = [sheets [i-1] .getName()];
退出
}
catch(err){
return#ERROR!


$ / code>

我的问题是如何修改脚本以跳过前两个工作表名称,并开始填充单元格中的脚本被调用的列表?



我试着改变 var i = 1 var i = 3 ,并且跳过前两个工作表名称,但它也创建为空白单元格。如何跳过前两个工作表名称并且不创建任何空白单元格?

解决方案

您有正确的想法,但您的输出数组将第一个项目放在第3位。相反,执行此操作:

  for(var i = 3; i< sheets .length + 1; i ++)out [i-2] = [sheets [i-1] .getName()]; 


I found code to list the names of all the sheets in Google Sheets (from here):

function SheetNames() { // Usage as custom function: =SheetNames( GoogleClock() )
try {
  var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets()
  var out = new Array( sheets.length+1 ) ;
  //out[0] = [ "Name" , "gid" ];
  for (var i = 1 ; i < sheets.length+1 ; i++ ) out[i] = [sheets[i-1].getName()];
  return out
}
catch( err ) {
  return "#ERROR!" 
}
}

My question is how can I modify the script to skip the first two sheet names and begin populating the list in the cell where the script is called?

I tried changing the var i = 1 to var i = 3 and that did skip the first two sheet names but it also created to blank cells. How do I skip the first two sheet names and not create any blank cells?

解决方案

You had the right idea, but your output array was placing the first item in position 3. Instead, do this:

for (var i = 3 ; i < sheets.length+1 ; i++ ) out[i-2] = [sheets[i-1].getName()];

这篇关于列出Google表格中的图表名称并跳过前两个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆