更改日历事件颜色
Changing calendar event color
我希望能够以编程方式更改日历事件的颜色。我正在阅读此文档,但不明白 "key" 在这里指的是什么:https://developers.google.com/google-apps/calendar/v3/reference/colors。是事件 ID 吗?
我还想知道是否可以通过电子表格更改日历事件的颜色。我有一个脚本可以将电子表格中的条目添加到日历中,但我也希望能够定义颜色。如果可能,请给我指点有用的阅读材料 material 或示例。
编辑 12/20/2015- 添加了工作脚本以添加事件:
function createEvent() {
var calendarId = 'MY_ID';
var event = {
summary: 'test',
description: 'test desc',
"end": {
"date": "2015-12-21"
},
"start": {
"date": "2015-12-21"
},
colorId: 10
};
event = Calendar.Events.insert(event, calendarId);
Logger.log('Event ID: ' + event.getId());
}
哦,您是否对 Google 缺乏这方面的文档感到困惑?别担心,我也是。Here's 数字(键)和相关颜色的图表。最后看起来像这样:
var event = {
summary: "Summarizing",
description: "Descriptive",
start: {
date: Utilities.formatDate(start, "GMT-5", "yyyy-MM-dd")
},
end: {
date: Utilities.formatDate(end, "GMT-5", "yyyy-MM-dd")
},
colorId: 10
};
event = Calendar.Events.insert(event, calendarId);
}
希望对您有所帮助!对于第二部分:应该可以,只要确保您使用的是 Google Calendar Advanced 服务即可。如果没有关于您要执行的操作的更多详细信息,则很难提供更多信息:/
旧post,但以防万一有人正在寻找一些示例代码。
以下代码将所有信息存储在电子表格中:
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Your Sheet Name")
var index = 2;
var lastRow = sheet.getLastRow();
for (;index <= lastRow; index++){
var title = sheet.getRange(index, 1, 1, 1).getValue();
var startTime = sheet.getRange(index, 2, 1, 1).getValue();
var endTime = sheet.getRange(index, 3, 1, 1).getValue();
var description = sheet.getRange(index, 4, 1, 1).getValue();
var location = sheet.getRange(index, 5, 1, 1).getValue();
var guests = sheet.getRange(index, 6, 1, 1).getValue();
var eventColour = sheet.getRange(index, 7, 1, 1).getValue();
var sendInvites = true;
var calendar = CalendarApp.getCalendarById("your Calendar ID").createEvent(title, startTime, endTime,
{description: description, location: location, guests: guests, sendInvites: sendInvites }).getId();
if (eventColour === "Condition1") CalendarApp.getEventById(calendar).setColor("10")
if (eventColour === "Condition2") CalendarApp.getEventById(calendar).setColor("11")
if (eventColour === "Condition3") CalendarApp.getEventById(calendar).setColor("12")
if (eventColour === "Condition4") CalendarApp.getEventById(calendar).setColor("13")
}// End of For Loop
}// End of Function
为了快速参考,我想我会加入并参考 Google 的 ColorEnum 文档,并在此处列出可用的日历颜色:
1 Pale Blue
2 Pale Green
3 Mauve
4 Pale Red
5 Yellow
6 Orange
7 Cyan
8 Gray
9 Blue
10 Green
11 Red
我希望能够以编程方式更改日历事件的颜色。我正在阅读此文档,但不明白 "key" 在这里指的是什么:https://developers.google.com/google-apps/calendar/v3/reference/colors。是事件 ID 吗?
我还想知道是否可以通过电子表格更改日历事件的颜色。我有一个脚本可以将电子表格中的条目添加到日历中,但我也希望能够定义颜色。如果可能,请给我指点有用的阅读材料 material 或示例。
编辑 12/20/2015- 添加了工作脚本以添加事件:
function createEvent() {
var calendarId = 'MY_ID';
var event = {
summary: 'test',
description: 'test desc',
"end": {
"date": "2015-12-21"
},
"start": {
"date": "2015-12-21"
},
colorId: 10
};
event = Calendar.Events.insert(event, calendarId);
Logger.log('Event ID: ' + event.getId());
}
哦,您是否对 Google 缺乏这方面的文档感到困惑?别担心,我也是。Here's 数字(键)和相关颜色的图表。最后看起来像这样:
var event = {
summary: "Summarizing",
description: "Descriptive",
start: {
date: Utilities.formatDate(start, "GMT-5", "yyyy-MM-dd")
},
end: {
date: Utilities.formatDate(end, "GMT-5", "yyyy-MM-dd")
},
colorId: 10
};
event = Calendar.Events.insert(event, calendarId);
}
希望对您有所帮助!对于第二部分:应该可以,只要确保您使用的是 Google Calendar Advanced 服务即可。如果没有关于您要执行的操作的更多详细信息,则很难提供更多信息:/
旧post,但以防万一有人正在寻找一些示例代码。 以下代码将所有信息存储在电子表格中:
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Your Sheet Name")
var index = 2;
var lastRow = sheet.getLastRow();
for (;index <= lastRow; index++){
var title = sheet.getRange(index, 1, 1, 1).getValue();
var startTime = sheet.getRange(index, 2, 1, 1).getValue();
var endTime = sheet.getRange(index, 3, 1, 1).getValue();
var description = sheet.getRange(index, 4, 1, 1).getValue();
var location = sheet.getRange(index, 5, 1, 1).getValue();
var guests = sheet.getRange(index, 6, 1, 1).getValue();
var eventColour = sheet.getRange(index, 7, 1, 1).getValue();
var sendInvites = true;
var calendar = CalendarApp.getCalendarById("your Calendar ID").createEvent(title, startTime, endTime,
{description: description, location: location, guests: guests, sendInvites: sendInvites }).getId();
if (eventColour === "Condition1") CalendarApp.getEventById(calendar).setColor("10")
if (eventColour === "Condition2") CalendarApp.getEventById(calendar).setColor("11")
if (eventColour === "Condition3") CalendarApp.getEventById(calendar).setColor("12")
if (eventColour === "Condition4") CalendarApp.getEventById(calendar).setColor("13")
}// End of For Loop
}// End of Function
为了快速参考,我想我会加入并参考 Google 的 ColorEnum 文档,并在此处列出可用的日历颜色:
1 Pale Blue
2 Pale Green
3 Mauve
4 Pale Red
5 Yellow
6 Orange
7 Cyan
8 Gray
9 Blue
10 Green
11 Red