Objective
I am trying to use the google script editor to import csv files on google drive into my google sheet. Can someone clarify to me what I'm misunderstanding about the script and what I need to tweak to allow me to paste multiple sheet requests into the below? Apologies if this is something straight forward, this is my first time using the script editor, and I'm not familiar with a lot of this.
Issue
At current my code only populates 1 sheets worth of data. as opposed to treating the second part as the next sheet that I want populated, with a different csv sheet ID.
What I've tried
- Changing the variables to be more unique to get the sheet to treat my variables as different, as I thought it was wiping each time.
- Reviewing other online help forums without luck of finding something similar that I can understand.
Current Code
function onOpen(e) {
SpreadsheetApp.getUi()
.createMenu('RefreshData')
.addItem('Run getCSV', 'getCSV')
.addToUi()
}
function getCSV() {
//ENTER YOUR CSV FILE ID IN THE getFileByID in the ""
var file = DriveApp.getFileById("<file_id>");
var csvFile = file.getBlob().getDataAsString();
var csvData = Utilities.parseCsv(csvFile);
//CHANGE SHEET NAME TO WHATEVER YOUR SHEET IS CALLED
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
sheet.clear();
sheet.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);
}
function getCSV() {
//ENTER YOUR CSV FILE ID IN THE getFileByID in the ""
var file = DriveApp.getFileById("<file_id2>");
var csvFile = file.getBlob().getDataAsString();
var csvData = Utilities.parseCsv(csvFile);
//CHANGE SHEET NAME TO WHATEVER YOUR SHEET IS CALLED
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2");
sheet.clear();
sheet.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);
}
getCSV(). In this case, would recommend you to rename one of these and call it from the other. - Sourabh Choraria