I've been working on importing csv files into specific Google Sheets using App scripts. Although my code seems to be functioning correctly, it's not producing any output. The approach I took was creating an array for the list of csv files and another array for the sheet names in the active spreadsheet. Then, I implemented an if loop where the data from the csv file will be pushed into the corresponding sheet based on the array indexes. This logic is wrapped within an outer for loop for iteration purposes. Below is the code snippet:
function importCSVFromGoogleDrive() {
var ss = SpreadsheetApp.getActiveSpreadsheet();// get the active spreadsheet
["Sheet1", "Sheet2", "Sheet3"].forEach(function (s) {
var sheetArray = ss.getSheetByName(s); // getSheetByName
var numSheets = sheetArray.length; // save sheets in Array
for (j = 0; j < numSheets; j++) { //loop to iterate
var fileArray = DriveApp.getFilesByName["Acsv","Bcsv"]; //get csv files as a list
var file = fileArray.length; // add the list into an array
var csvData = Utilities.parseCsv(file.getBlob().getDataAsString()); // parse csv data
if(numSheets==csvData){ // if array Index No of numSheets equals to index of file array
numSheets.push(csvData);// push csv data into the sheet
numSheets.clearContents(); //clear current contents in the sheet
numSheets.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData); // set values to the sheet
}
}
})
}
The code is executing without errors, yet no data is being transferred from the csv file to the sheet. Can you shed some light on why this might be happening?