Estoy tratando de seleccionar una matriz de las hojas de Google para crear eventos de calendario de Google basados en eso. El fragmento de código a continuación funciona bien y hace el trabajo. Pero solo quiero poder seleccionar el rango que tiene el valor de "seleccionar" en su columna D. Sé que probablemente sea una respuesta muy fácil, pero soy nuevo en JS.
function calendarSync() { var spreadSheet = SpreadsheetApp.getActiveSheet; var eventCal = CalendarApp.getCalendarById(calendarId); // Below instead of selecting the entire range I only need the rows that have a value of "select" in their D cell. var eventArray = spreadSheet.getRange("A1:D100").getValues(); for (x=0; x<eventMatrix.length; x++){ var calEvent = eventArray[x]; var eventName = calEvent[0] var startTime = calEvent[1]; var endTime = calEvent[2]; eventCal.createEvent(eventName, startTime, endTime); }En su situación, ¿qué tal la siguiente modificación?
var spreadSheet = SpreadsheetApp.getActiveSheet; var eventCal = CalendarApp.getCalendarById(calendarId); // Below instead of selecting the entire range I only need the rows that have a value of "select" in their D cell. var eventArray = spreadSheet.getRange("A1:D100").getValues(); var spreadSheet = SpreadsheetApp.getActiveSheet(); // Please add () var eventCal = CalendarApp.getCalendarById(calendarId); var eventArray = spreadSheet.getRange("A1:D100").getValues().filter(r => r[3] == "select");eventArray tiene los valores que select se incluye en la columna "D".