I created a Google Spreadsheet that revolves around recurring events. The input for the recurring events are coded to populate my Google Calendar. When I run the code it works as it should except it only runs the first row. I know it has something to do with my Range argument. I have even been able to select which row I wanted to run by doing ss.getRange("what ever number row here",2).getValue()
. But I have never been able to run all of the rows and I can not figure out how to do it.
function onOpen(){
SpreadsheetApp.getUi().createMenu("Pop").addItem("Create Event",
"recurring_event").addToUi()
}
function recurring_event() {
var row = 2
var ws = SpreadsheetApp.getActiveSpreadsheet();
var ss = ws.getSheetByName("sheet6")
var title = ss.getRange(row, 1,1000).getValue()
var start_date = ss.getRange(row, 2,1000).getValue()
var duration = ss.getRange(row, 3,1000).getValue()
var repetition = ss.getRange(row, 4,1000).getValue()
var end_date = new Date(start_date)
end_date.setTime(end_date.getTime()+1000*60*duration)
var recurrence =""
if(repetition=="3 Month") recurrence = CalendarApp.newRecurrence().
addMonthlyRule().interval(3)
else if(repetition=="6 Month") recurrence = CalendarApp.newRecurrence().
addMonthlyRule().interval(6)
else if(repetition=="annually") recurrence = CalendarApp.newRecurrence().
addYearlyRule()
CalendarApp.createEventSeries(title, start_date, end_date,recurrence)
}
I have tried doing ss.getRange(2,3,1000).getValue
hoping that it would return the next 1000 rows but it did not. I have also played with ss.getDataRange()
but I don’t know if I am doing it correctly. I just am lost as to what might be the next step.
1
From the question
I have tried doing ss.getRange(2,3,1000).getValue hoping that it would return the next 1000 rows but it did not.
The SpreadsheetApp.Range.getValue
method returns the value of only one cell, no matter how many cells have the range. To get the values of all cells in the range, instead use SpreadsheetApp.Range.getValues
.
Just so you know, you should update your script to handle the suggested method’s response. For details about how to read and write values to Google Sheets, please see https://developers.google.com/apps-script/guides/sheets.
2