Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

362
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!