Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

351
Vistas
forEach matriz obtiene error TypeError: no se puede leer la propiedad 'forEach' de indefinido

estoy tratando de limpiar algunas hojas, individualmente hago que funcione sin comentar y cambiando el nombre de la hoja

 function doClean(sheet) { // var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Resultado"); var LR = sheet.getLastRow(); var LC = sheet.getLastColumn(); sheet.getRange(1,1,LR,LC).getDisplayValues() sheet.createTextFinder("-").matchEntireCell(true).replaceAllWith(""); sheet.createTextFinder("0").matchEntireCell(true).replaceAllWith(""); sheet.createTextFinder("0,00").matchEntireCell(true).replaceAllWith(""); sheet.createTextFinder("0,0000").matchEntireCell(true).replaceAllWith(""); };

pero cuando trato de agrupar en matriz y ejecutar con foreach

 function doCleanSheets() { var sheet = ["BLC", "Balanço", "DRE", "Resultado", "FLC", "Fluxo", "DVA", "Valor"]; SpreadsheetApp.getActive().sheet.forEach(doClean); };

estoy recibiendo un error

TypeError: no se puede leer la propiedad 'forEach' de doCleanSheets indefinido @ - 10x_to_11x.gs:87

la línea 87 es SpreadsheetApp.getActive().sheet.forEach(doClean);

busqué el error, pero los resultados fueron mucho más complejos que mi caso, y no pude aplicar

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Cuando vi su secuencia de comandos, desafortunadamente, SpreadsheetApp.getActive() no tiene propiedad de sheet . Por esto, tal error ocurre. Cuando desee utilizar los nombres de hoja de sheet en forEach, ¿qué le parece la siguiente modificación?

Guión modificado:

Modifique doCleanSheets de la siguiente manera.

 function doCleanSheets() { var sheet = ["BLC", "Balanço", "DRE", "Resultado", "FLC", "Fluxo", "DVA", "Valor"]; var sheets = SpreadsheetApp.getActive().getSheets().filter(s => sheet.includes(s.getSheetName())); sheets.forEach(doClean); }

Referencias:

  • getActive()
  • obtenerHojas()
about 4 years ago · Santiago Trujillo Denunciar

0

Pruébalo de esta manera:

 function doClean(sheet) { var LR = sheet.getLastRow(); var LC = sheet.getLastColumn(); sheet.getRange(1, 1, LR, LC).getDisplayValues() sheet.createTextFinder("-").matchEntireCell(true).replaceAllWith(""); sheet.createTextFinder("0").matchEntireCell(true).replaceAllWith(""); sheet.createTextFinder("0,00").matchEntireCell(true).replaceAllWith(""); sheet.createTextFinder("0,0000").matchEntireCell(true).replaceAllWith(""); }; function doCleanSheets() { var sheet = ["BLC", "Balanço", "DRE", "Resultado", "FLC", "Fluxo", "DVA", "Valor"]; sheet.forEach(sh => doClean(SpreadsheetApp.getActive().geSheetByName(sh))); };
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda