Reputation: 1175
I am trying to build a nodejs application, which will run once in every week. Its job is to fetch data from a Google Spreadsheet between last week and today. Basically, I want to get data added during last week.
I believe this is what I've to use: https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet but do let me know if there's something better.
I think SpreadSheet.getActiveSheet().getRange()
will return an array with all the data but I am not sure where I can add some kind of query to fetch data by dates.
Something like
SpreadSheet.getActiveSheet().getRange(date > lastWeek && date < today)
Is there any way to implement this?
Upvotes: 0
Views: 950
Reputation: 151
As far as i know, there's no way to know when a row was added, as such your range wouldn't work.
The way i would do this is keep a timestamp on each row for when it was added and iterate over all the data to find the values that fit. (You could also keep somewhere the last row read and start from there).
var sheet = SpreadsheetApp.openById(id).getSheetByName(name)
var data = sheet.getDataRange().getValues();
for (var i = 0 ; i < data.length; i++){
if (data[i][index_of_timestamp] < today && data[i][index_of_timestamp] > lastWeek){
realData.push(data[i]);
}
}
Upvotes: 1