I've got a script that's importing a CSV from a location on G-Drive - I just need it to import the first 300 rows, as opposed to all 2000 rows. What am I missing?
function importCSVFromGoogleDrive() {
var fSource = DriveApp.getFolderById('xxxxxxxxxxxx'); // reports_folder_id = id of folder where csv is saved
var file = DriveApp.getFilesByName("content.csv").next();
var csvData = Utilities.parseCsv(file.getBlob().getDataAsString());
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);
}
First 300 lines of csv file
function importCSVFromGoogleDrive() {
var folder = DriveApp.getFolderById('xxxxxxxxxxxx');
var files = folder.getFilesByName("content.csv");
var n=0;
while(files.hasNext()) {
var file=files.next();
n++;
}
if(n==1) {
var csvData = Utilities.parseCsv(file.getBlob().getDataAsString()).slice(0,300);
SpreadsheetApp.getActiveSheet().getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);
}else{
SpreadsheetApp.getUi().alert("More Than One File with that name");
}
}
Array.slice()
I tested with a csv file of my own.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With