im trying to clean some sheets, individually i make it work uncommenting and changing sheet name
JavaScript
x
14
14
1
function doClean(sheet)
2
{
3
// var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Resultado");
4
5
var LR = sheet.getLastRow();
6
var LC = sheet.getLastColumn();
7
8
sheet.getRange(1,1,LR,LC).getDisplayValues()
9
sheet.createTextFinder("-").matchEntireCell(true).replaceAllWith("");
10
sheet.createTextFinder("0").matchEntireCell(true).replaceAllWith("");
11
sheet.createTextFinder("0,00").matchEntireCell(true).replaceAllWith("");
12
sheet.createTextFinder("0,0000").matchEntireCell(true).replaceAllWith("");
13
};
14
but when when i try to group in array and execute with foreach
JavaScript
1
5
1
function doCleanSheets() {
2
var sheet = ["BLC", "Balanço", "DRE", "Resultado", "FLC", "Fluxo", "DVA", "Valor"];
3
SpreadsheetApp.getActive().sheet.forEach(doClean);
4
};
5
im getting error
TypeError: Cannot read property ‘forEach’ of undefined doCleanSheets @ – 10x_to_11x.gs:87
line 87 is SpreadsheetApp.getActive().sheet.forEach(doClean);
searched for error, but results were way more complex than my case, and i couldnt apply
Advertisement
Answer
When I saw your script, unfortunately, SpreadsheetApp.getActive()
has no property of sheet
. By this, such error occurs. When you want to use the sheet names of sheet
in the forEach, how about the following modification?
Modified script:
Please modify doCleanSheets
as follows.
JavaScript
1
6
1
function doCleanSheets() {
2
var sheet = ["BLC", "Balanço", "DRE", "Resultado", "FLC", "Fluxo", "DVA", "Valor"];
3
var sheets = SpreadsheetApp.getActive().getSheets().filter(s => sheet.includes(s.getSheetName()));
4
sheets.forEach(doClean);
5
}
6