teaklee
Thành viên mới
- Tham gia
- 11/3/13
- Bài viết
- 41
- Được thích
- 1
Mình tìm dc code này, dùng để merge các file trong cùng 1 folder lại, nhưng khi mình chạy thì nó báo lỗi
Lúc thì nó báo:
Error
TypeError: Cannot read property 'getRange' undefine
Mong các bác hỗ trợ ạ
Mã:
function myFunction() {
var myFolder = DriveApp.getFolderById("15fzUjiZsPbvchmFBy0UTkitUkHuA4pfQ");
var spreadSheets = myFolder.getFilesByType("application/vnd.google-apps.spreadsheet");
var master_files = DriveApp.getFilesByName("MergedNew")
if (master_files.hasNext()){
var master_file=master_files.next();
var newSpreadSheet = SpreadsheetApp.openById(master_file.getId());
}
else {
var newSpreadSheet = SpreadsheetApp.create("MergedNew");
newSpreadSheet.getSheets()[0].setName("B data");
}
var bSheet = newSpreadSheet.getSheetByName("B data");
while(spreadSheets.hasNext())
{
var sheet = spreadSheets.next();
var spreadSheet = SpreadsheetApp.openById(sheet.getId());
var sh = spreadSheet.getSheetByName('T7-2022');
var data = sh.getRange(2,1,sh.getMaxRows(),sh.getMaxColumns()).getValues();
var filtered_data = data.filter(function (row) {
return row[0] != ""; //
});
if (bSheet.getLastRow() == 0){
var headers = sh.getRange(1,1,1,sh.getMaxColumns()).getValues();
bSheet.getRange(1,1,1,sh.getMaxColumns()).setValues(headers);
}
bSheet.getRange(bSheet.getLastRow()+1,1,filtered_data.length,filtered_data[0].length).setValues(filtered_data);
}
}
Lúc thì nó báo:
Lúc thì nó lại báoError
TypeError: Cannot read property 'getRange' of null
myFunction
@ Code.gs:23
Error
TypeError: Cannot read property 'getRange' undefine
Mong các bác hỗ trợ ạ