Google sheets 仅在一个选项卡中粘贴信息

Google sheets 仅在一个选项卡中粘贴信息,google-sheets,Google Sheets,我有一个小问题。在我的代码中,我从谷歌日历中提取约会。工作非常好,除了我希望它只在一个选项卡(表1)上工作,而不是在其他选项卡上。如何指向该选项卡粘贴信息 如果我在Sheet2上编辑,它会将信息粘贴到那里 function export_gcal_to_gsheet(){ // // Export Google Calendar Events to a Google Spreadsheet // // This code retrieves events between 2 dates for

我有一个小问题。在我的代码中,我从谷歌日历中提取约会。工作非常好,除了我希望它只在一个选项卡(表1)上工作,而不是在其他选项卡上。如何指向该选项卡粘贴信息

如果我在Sheet2上编辑,它会将信息粘贴到那里

function export_gcal_to_gsheet(){

//
// Export Google Calendar Events to a Google Spreadsheet
//
// This code retrieves events between 2 dates for the specified calendar.
// It logs the results in the current spreadsheet starting at cell A2 listing the events,
// dates/times, etc and even calculates event duration (via creating formulas in the spreadsheet) and formats the values.
//
// I do re-write the spreadsheet header in Row 1 with every run, as I found it faster to delete then entire sheet content,
// change my parameters, and re-run my exports versus trying to save the header row manually...so be sure if you change
// any code, you keep the header in agreement for readability!
//
// 1. Please modify the value for mycal to be YOUR calendar email address or one visible on your MY Calendars section of your Google Calendar
// 2. Please modify the values for events to be the date/time range you want and any search parameters to find or omit calendar entires
// Note: Events can be easily filtered out/deleted once exported from the calendar
// 
// Reference Websites:
// https://developers.google.com/apps-script/reference/calendar/calendar
// https://developers.google.com/apps-script/reference/calendar/calendar-event
//

var mycal = "info@hhhhh.nl";
var cal = CalendarApp.getCalendarById(mycal);

// Optional variations on getEvents
// var events = cal.getEvents(new Date("January 3, 2014 00:00:00 CST"), new Date("January 14, 2014 23:59:59 CST"));
// var events = cal.getEvents(new Date("January 3, 2014 00:00:00 CST"), new Date("January 14, 2014 23:59:59 CST"), {search: 'word1'});
// 
// Explanation of how the search section works (as it is NOT quite like most things Google) as part of the getEvents function:
//    {search: 'word1'}              Search for events with word1
//    {search: '-word1'}             Search for events without word1
//    {search: 'word1 word2'}        Search for events with word2 ONLY
//    {search: 'word1-word2'}        Search for events with ????
//    {search: 'word1 -word2'}       Search for events without word2
//    {search: 'word1+word2'}        Search for events with word1 AND word2
//    {search: 'word1+-word2'}       Search for events with word1 AND without word2
//
var events = cal.getEvents(new Date("January 12, 2014 00:00:00 CST"), new Date("May 18, 2014 23:59:59 CST"), {search: '-pauze'});


var sheet = SpreadsheetApp.getActiveSheet();

// Uncomment this next line if you want to always clear the spreadsheet content before running - Note people could have added extra columns on the data though that would be lost
// sheet.clearContents();  

// Create a header record on the current spreadsheet in cells A1:N1 - Match the number of entries in the "header=" to the last parameter
// of the getRange entry below
var header = [["Client", "Notitie", "Begin", "Eind", "Duur"]]
var range = sheet.getRange(1,1,1,5);
range.setValues(header);


// Loop through all calendar events found and write them out starting on calulated ROW 2 (i+2)
for (var i=0;i<events.length;i++) {
var row=i+2;
var myformula_placeholder = '';
// Matching the "header=" entry above, this is the detailed row entry "details=", and must match the number of entries of the GetRange entry below
// NOTE: I've had problems with the getVisibility for some older events not having a value, so I've had do add in some NULL text to make sure it does not error
var details=[[events[i].getTitle(), events[i].getDescription(), events[i].getStartTime(), events[i].getEndTime(), myformula_placeholder]];
var range=sheet.getRange(row,1,1,5);
range.setValues(details);

// Writing formulas from scripts requires that you write the formulas separate from non-formulas
// Write the formula out for this specific row in column 7 to match the position of the field myformula_placeholder from above: foumula over columns F-E for time calc
var cell=sheet.getRange(row,5);
cell.setFormula('=(HOUR(D' +row+ ')+(MINUTE(D' +row+ ')/60))-(HOUR(C' +row+ ')+(MINUTE(C' +row+ ')/60))');
cell.setNumberFormat('.0');

}
}
function export\u gcal\u to\u gsheet(){
//
//将Google日历事件导出到Google电子表格
//
//此代码检索指定日历的两个日期之间的事件。
//它将结果记录在当前电子表格中,从单元格A2开始列出事件,
//日期/时间等,甚至计算事件持续时间(通过在电子表格中创建公式)并格式化值。
//
//每次运行时,我都会在第1行重新编写电子表格标题,因为我发现删除整个工作表内容的速度要快得多,
//更改我的参数,并重新运行我的导出,而不是尝试手动保存标题行…因此,请确保如果您更改
//任何代码,你都要保证标题的可读性!
//
//1.请将mycal的值修改为您的日历电子邮件地址或在您的Google日历的“我的日历”部分可见的地址
//2.请将事件的值修改为所需的日期/时间范围,并修改任何搜索参数以查找或忽略日历实体
//注意:一旦从日历中导出,事件就可以很容易地过滤/删除
// 
//参考网站:
// https://developers.google.com/apps-script/reference/calendar/calendar
// https://developers.google.com/apps-script/reference/calendar/calendar-event
//
var mycal=”info@hhhhh.nl";
var cal=CalendarApp.getCalendarById(mycal);
//getEvents的可选变体
//var事件=cal.getEvents(新日期(“2014年1月3日00:00:00 CST”)、新日期(“2014年1月14日23:59:59 CST”);
//var events=cal.getEvents(新日期(“2014年1月3日00:00:00 CST”)、新日期(“2014年1月14日23:59:59 CST”)、{search:'word1'};
// 
//作为getEvents函数的一部分,解释搜索部分的工作原理(因为它与Google的大多数内容不太一样):
//{search:'word1'}使用word1搜索事件
//{search:'-word1'}搜索不带word1的事件
//{search:'word1 word2'}仅搜索具有word2的事件
//{search:'word1-word2'}搜索带有????
//{search:'word1-word2'}搜索没有word2的事件
//{search:'word1+word2'}搜索具有word1和word2的事件
//{search:'word1+-word2'}搜索包含word1和不包含word2的事件
//
var events=cal.getEvents(新日期(“2014年1月12日00:00:00 CST”)、新日期(“2014年5月18日23:59:59 CST”)、{search:'-pauze'});
var sheet=SpreadsheetApp.getActiveSheet();
//如果您希望在运行之前始终清除电子表格内容,请取消对下一行的注释-注意,人们可能会在数据上添加额外的列,但这将丢失
//sheet.clearContents();
//在单元格A1:N1中的当前电子表格上创建标题记录-将“header=”中的条目数与最后一个参数匹配
//下面的getRange条目的
var头=[[“客户端”、“Notitie”、“开始”、“Eind”、“Duur”]]
var范围=sheet.getRange(1,1,1,5);
范围。设置值(标题);
//循环查看找到的所有日历事件,并从计算的第2行(i+2)开始写出它们

对于(var i=0;i使用函数getSheetByName来执行此操作,例如:

var ss = SpreadsheetApp.getActiveSpreadsheet();  
var sheet = ss.getSheetByName("sheet1");