![](/img/trans.png)
[英]How to tell if two cells are equal in Google Apps Script for Google Spreadsheet
[英]Google Apps Script (Spreadsheet) - selecting an array in spreadsheet based on a condition in cells
我正在尝试 select 来自谷歌表格的数组,以基于该数组创建谷歌日历事件。 下面的代码块运行得很好并完成了工作。 但我希望能够仅 select 在 D 列中具有“选择”值的范围。我知道这可能是一个非常简单的答案,但我是 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);
}
在您的情况下,后续修改如何?
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
具有select
包含在“D”列中的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.