简体   繁体   English

forEach 数组出现错误类型错误:无法读取未定义的属性“forEach”

[英]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名称时,下面的修改如何?

Modified script:修改脚本:

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

References:参考:

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.

相关问题 错误:TypeError:无法读取未定义的属性“forEach” - Error : TypeError: Cannot read property 'forEach' of undefined 反应表获取问题类型错误:无法读取未定义的属性“forEach” - React table getting issue TypeError: Cannot read property 'forEach' of undefined TypeError:无法在 Array.forEach 处读取未定义的属性“名称” - TypeError: Cannot read property 'name' of undefined, at Array.forEach 错误类型错误:无法读取 Angular 中未定义的属性“forEach” - ERROR TypeError:Cannot read property 'forEach' of undefined in Angular 类型错误:无法读取未定义的属性“forEach” - TypeError: Cannot read property 'forEach' of undefined UnhandledPromiseRejectionWarning: TypeError: 无法读取未定义的属性“forEach” - UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'forEach' of undefined TypeError:无法读取未定义 React 的属性“forEach” - TypeError: Cannot read property 'forEach' of undefined React 类型错误:无法读取未定义 Javascript 的属性“forEach” - TypeError: Cannot read property 'forEach' of undefined Javascript 类型错误:无法读取未定义的属性“forEach”,javascript - TypeError: Cannot read property 'forEach' of undefined , javascript 为什么我收到错误“UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'forEach' of undefined”? - Why am I getting the error “UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'forEach' of undefined”?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM