I am trying to import data from one spreadsheet to another. Ideally, this code should get data from one spreadsheet, store it into a 2d array, then print all this data into another spreadsheet. The process that involves printing the values is the one that fails and throws the error Exception: Service error: Spreadsheets
var pasteSheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()
uploadFolder = DriveApp.getFolderById('someID')
obtainAndImportData(uploadFolder)
function obtainAndImportData(uploadFolder){
try{
var internalFiles = uploadFolder.getFiles()
} catch{
return
}
while (internalFiles.hasNext()){
try{
var file = internalFiles.next()
} catch {
break
}
var fileID = file.getId()
var copySheet = SpreadsheetApp.openById(fileID).getSheets()[0]
var Cvals = copySheet.getRange("C1:C" + copySheet.getLastRow()).getValues()
var ldr = Cvals.length;
var Csheet = pasteSheet.getRange("C1:C" + pasteSheet.getLastRow()).getValues()
var lstv = Csheet.length;
var allRows = []
for (i = 0;i < ldr;i++){
allRows.push(copySheet.getRange(`B${i + 3}:P${i + 3}`).getValues()[0])
}
console.log(allRows)
var rangeToUnify = pasteSheet.getRange(lstv + 1,1,allRows.length,allRows[0].length)
rangeToUnify.setValues(allRows) // this line throws the error
}
}
I have read this might be due to big amounts of data, but I have tested with only one line, yet it keeps failing.
Data has columns from A to P and no specific number of rows. Maybe it is important to note that the file(s) from which I want the information, is originally ".xslx" but then is opened as Google sheets file.