有没有办法向Google电子表格添加脚本,以便从工作表上的某些字段中获取信息,并将其作为活动添加到我的Google日历中。 例如。日期和时间以及活动标题?
答案 0 :(得分:0)
您可以在电子表格中添加自定义菜单,以便在您选择菜单项时触发代码运行。
在您的代码中添加onOpen()
简单触发器功能,以便在电子表格打开时创建新菜单:
function onOpen() { //Runs when spreadsheet is opened
SpreadsheetApp.getUi()
.createMenu('Custom Menu')
//Run a function named fncAddToCalender when menu item is choosen
.addItem('Display User Dialog', 'fncAddToCalender')
.addToUi();
};
function fncAddToCalender() {
var arrayOfData = fncGetData(); //Runs the function that gets the data
fncAddCalenderEvent(arrayOfData); //Runs the function that adds the calender event
};
function fncGetData() {
//Get data from Spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0]; //Get the first sheet, index zero
var range = sheet.getRange(1, 1, 10, 3); //Get a REFERENCE to a range of cells
var values = range.getValues(); //Get the values out of the range
return values; //Sends data back to the function that called this function
};
function fncAddCalenderEvent(argDataToAdd) {
//Code to add calender event
};