Estoy intentando ejecutar un script que copiará información de varias hojas diferentes a un archivo diferente. Tengo problemas con la función forEach . El error que estoy recibiendo es:
Error
ReferenceError: las hojas no están definidas copy @ Code.gs: 9 copyInfo @ Code.gs: 4
function copyInfo() { var sheets = SpreadsheetApp.getActive().getSheets(); // get all sheets sheets.forEach(copy) } function copy() { var sheetName = sheets.getActiveSheet.getName(); if(sheetName.includes("*")) var copySheet = SpreadsheetApp.getActiveSheet(); var sheetName=copySheet.getName(); var pasteSpreadsheet = SpreadsheetApp.openById("1NXmdq6yCKC6oiDAQNXcovj85697__rCeVJiIT_ou_gI"); //Create new sheet if one doesn't exist var newSheet = pasteSpreadsheet.getSheetByName(sheetName); if (newSheet != null) pasteSpreadsheet.deleteSheet(newSheet); newSheet = pasteSpreadsheet.insertSheet(); newSheet.setName(sheetName); //Copy and paste data // Clear the Google Sheet before copy newSheet.clear({contentsOnly: true}); // get source range var source = copySheet.getRange("B2:B"); var values = source.getValues(); // get destination range var destination = newSheet.getRange(1,1,values.length,values[0].length); // copy values to destination range destination.setValues(values); } function copyInfo() { const dontcopy = ["Sh1","Sh2",...]; var sheets = SpreadsheetApp.getActive().getSheets(); // get all sheets sheets.filter(sh => !~dontcopy.indexOf(sh.getName()).forEach(s => { s.activate(); copy(); }); }Si crea una función para usar con forEach, esa función debe aceptar un elemento individual como parámetro. En este caso, cada "hoja" de SpreadsheetApp.getActive().getSheets() se pasará como el primer parámetro a su función de copia, pero la función de copia no acepta ningún parámetro tal cual.
function copy(sheet) { var sheetName = sheet.getName(); if(sheetName.includes("*")) ... }