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
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?
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); }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))); };