Reputation: 63
I have some code for Google Macros that allows me to import all the rows in a particular CSV into Google Sheets. However, I'm having some issues synchronizing my uploads with other calculations I have taking place which leads to time out issues.
I think the easiest way to fix this will be to just import a specific range of cells and do that a couple of times.
Please suggest how I can modify the code below (which works) to import say Rows 1 to 2000.
function importCSVFromGoogleDrive() {
var file = DriveApp.getFilesByName("DualCreditExport.csv").next();
var csvData = Utilities.parseCsv(file.getBlob().getDataAsString());
var sheet = SpreadsheetApp.getActive().getSheetByName('CURRENT');
sheet.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);
}
Upvotes: 0
Views: 165
Reputation: 7973
You can do it as follows:
var start = 0; var numRows =2000;
sheet.getRange(start+1, 1, numRows, csvData[0].length).setValues(csvData.slice(start, start+numRows));
Note that the getRange function is defined as follows:
getRange(row, column, numRows, numColumns)
and that the row and column starts from 1 here and in an array it starts from 0.
Upvotes: 2