This program tries to bring all the data in one spreadsheet and paste it into another spreadsheet. Firstly, it gets all files inside a folder (all of which will be spreadsheets), then it gets the values of a certain range and stores them into an array; after that, it goes to another spreadsheet and tries to set the values of the array into the first row with no data; finally, it moves the file where the data was stored in the first place.
var uploadG = DriveApp.getFolderById('')
var moveToG = DriveApp.getFolderById('')
function obtainAndImportData(uploadFolder){
var internalFiles = uploadFolder.getFiles()
while (internalFiles.hasNext()){
var file = internalFiles.next()
var fileID = file.getId()
var copySheet = SpreadsheetApp.openById(fileID).getSheets()[0] // reads file by file and gets their first spreadsheet
var Cvals = copySheet.getRange("C1:C").getValues()
var lastToValue = Cvals.filter(String).length-2 // gets last row with data
var Csheet = pasteSheet.getRange("C1:C").getValues()
var lastSheetToValue = Csheet.filter(String).length // gets last row with data
var allRows = []
for (i = 0;i = lastToValue;i++){
allRows[i] = copySheet.getRange(`B${i+3}:P${i+3}`).getValues()
} // gets row and then stores it into an array
var rangeToUnify = pasteSheet.getRange(`B${lastSheetToValue+1}:P${lastSheetToValue + lastToValue + 1}`)
rangeToUnify.setValues(allRows) //inserts data from old spreadsheet into this new one
file.moveto(moveToG) // moves file
}
}
I think it should work fine, but the program just never completes its execution. Never inserts the data, and never moves files, but it doesn't throw any error either.
Note: The files this program is reading start as .xslx files, which are saved as Google Spreadsheets once they're uploaded to Google Drive. (maybe that is the problem, but I don't really know how to solve it)