我試圖清理一些床單,我單獨讓它作業,取消注釋和更改作業表名稱
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("");
};
但是當我嘗試在陣列中分組并使用 foreach 執行時
function doCleanSheets() {
var sheet = ["BLC", "Balan?o", "DRE", "Resultado", "FLC", "Fluxo", "DVA", "Valor"];
SpreadsheetApp.getActive().sheet.forEach(doClean);
};
我收到錯誤
型別錯誤:無法讀取未定義的 doCleanSheets @ 的屬性“forEach” - 10x_to_11x.gs:87
第 87 行是SpreadsheetApp.getActive().sheet.forEach(doClean);
搜索錯誤,但結果比我的情況復雜得多,我無法申請
uj5u.com熱心網友回復:
不幸的是,當我看到您的腳本時,SpreadsheetApp.getActive()它沒有sheet. 這樣,就會發生這樣的錯誤。當你想sheet在forEach中使用sheet名時,下面的修改怎么樣?
修改后的腳本:
請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);
}
參考:
- 獲取活動()
- 獲取表格()
uj5u.com熱心網友回復:
試試這種方式:
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)));
};
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/462984.html
