Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌应用程序脚本-按选项卡颜色获取工作表_Javascript_Google Apps Script_Google Sheets - Fatal编程技术网

Javascript 谷歌应用程序脚本-按选项卡颜色获取工作表

Javascript 谷歌应用程序脚本-按选项卡颜色获取工作表,javascript,google-apps-script,google-sheets,Javascript,Google Apps Script,Google Sheets,我很好奇,是否有一种方法可以通过谷歌脚本中标签的颜色来获取表单 我目前使用此数组按名称抓取图纸: 函数AddRow(){ var ss=SpreadsheetApp.openById('spreadsheetId'); 风险值承包商表,i,L,表; 承包商表=[ “员工1的时间表”, “员工2的时间表”, “员工3的时间表”, “员工4的时间表”, “员工5的时间表”, “员工6的时间表”, “员工7的时间表” ] L=承包商表的长度; 对于(i=0;i试试这样的方法 function addR

我很好奇,是否有一种方法可以通过谷歌脚本中标签的颜色来获取表单

我目前使用此数组按名称抓取图纸:

函数AddRow(){
var ss=SpreadsheetApp.openById('spreadsheetId');
风险值承包商表,i,L,表;
承包商表=[
“员工1的时间表”,
“员工2的时间表”,
“员工3的时间表”,
“员工4的时间表”,
“员工5的时间表”,
“员工6的时间表”,
“员工7的时间表”
]
L=承包商表的长度;

对于(i=0;i试试这样的方法

function addRow() {
SpreadsheetApp.openById('xxxxxxxxxxxxxxxyPz4').getSheets()
    .filter(function (sh) {
        return sh.getTabColor() == '#ff9900'; //change to match color
    }).forEach(function (sh) {
        sh.insertRowAfter(sh.getLastRow());
    })
}

这可以使用现有的方法轻松完成:

function getSheetsWithTabColor_(colorHex, allSheets) {
  if (!allSheets || !allSheets.length)
    allSheets = SpreadsheetApp.getActive().getSheets();
  return allSheets.filter(function (sheet) { return sheet.getTabColor() === colorHex; });
}

function foo() {
  const sheets = SpreadsheetApp.getActive().getSheets();
  const timesheets = getSheetsWithTabColor_("some color hex", sheets);
  timesheets.forEach(function (sheet) {
    /** do your stuff that should be done on sheets with this color tab */
  });
}
参考资料