Home>

Use Google gas to load the spreadsheet data in a specific folder,
We are making a mechanism to aggregate.
The name of the sheet I want to import is a specific name, and I want to import the data of the matching sheet name
The following error occurred:

TypeError: Undefined method "getRange" cannot be called. (Line 23, file "Data Aggregation") do not display

// For data aggregation
function aggregateData1 () {

var targetFolder = DriveApp.getFoldersByName ('Aggregate'). next ();
var files = targetFolder.getFiles ();

var outputSheet = SpreadsheetApp.getActiveSpreadsheet (). getSheetByName ('Raw Data_Aggregation');
if (! outputSheet) {
var outputSheet = SpreadsheetApp.getActiveSpreadsheet (). insertSheet ('Raw_Data_Aggregation');
}
outputSheet.clear ();

var curRow = 1;
var fileList = [];
while (files.hasNext ()) {
var file = files.next ();

var spreadsheet = SpreadsheetApp.open (file);
var sh000 = spreadsheet.getSheetByName ('Aggregating_Original') [0];

var data000 = sh000.getRange (). getValues ​​();
fileList.push ({"fileName" ;: file.getName ()});
var lastRow = outputSheet.getLastRow () + 1;

for (var i = 1;i<lastRow;i ++) {
if (data000 [i] [100] ==='') {
sh000.getRange (i + 1,1,1,25) .copyTo (outputSheet.getRange (lastRow +1,5));
sh000.getRange (i + 1,100) .setValue ("Done");
lastRow ++;

}

return fileList;

}

}
}

gas
Tried Supplemental information (FW/tool version etc.)

is
Data of a specific sheet name (and "Done" is not entered in the designated cell) is transferred to the consolidated sheet.
The cell of the sheet that has been posted is said to be "done".

  • Answer # 1

    var sh000 = spreadsheet.getSheetByName ('Aggregation_Original') [0];


    [0] here is unnecessary, ↓ this

    var sh000 = spreadsheet.getSheetByName ('Aggregation_Original');
    var data000 = sh000.getDataRange (). getValues ​​();


    As I added, getRange takes a range, so an error occurs if there is no range.
    You can use lastrow, but if you just want to copy all the data, you can use .getDataRange () .

Related articles