[英]forEach array getting error TypeError: Cannot read property 'forEach' of undefined
im trying to clean some sheets, individually i make it work uncommenting and changing sheet name我试图清理一些床单,我单独让它工作,取消注释并更改床单名称
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("");
};
but when when i try to group in array and execute with foreach但是当我尝试在数组中分组并使用 foreach 执行时
function doCleanSheets() {
var sheet = ["BLC", "Balanço", "DRE", "Resultado", "FLC", "Fluxo", "DVA", "Valor"];
SpreadsheetApp.getActive().sheet.forEach(doClean);
};
im getting error我收到错误
TypeError: Cannot read property 'forEach' of undefined doCleanSheets @ - 10x_to_11x.gs:87
类型错误:无法读取未定义的 doCleanSheets 的属性“forEach”@ - 10x_to_11x.gs:87
line 87 is SpreadsheetApp.getActive().sheet.forEach(doClean);
第 87 行是
SpreadsheetApp.getActive().sheet.forEach(doClean);
searched for error, but results were way more complex than my case, and i couldnt apply搜索错误,但结果比我的情况复杂得多,我无法申请
When I saw your script, unfortunately, SpreadsheetApp.getActive()
has no property of sheet
.不幸的是,当我看到您的脚本时,
SpreadsheetApp.getActive()
没有sheet
的属性。 By this, such error occurs.这样,就会出现这样的错误。 When you want to use the sheet names of
sheet
in the forEach, how about the following modification?当你想在forEach中使用
sheet
的sheet名称时,下面的修改如何?
Please modify doCleanSheets
as follows.请修改
doCleanSheets
如下。
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);
}
Try it this way:试试这样:
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)));
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.