将谷歌日历导出到护目镜表-从最新到最旧排序的问题



如何让这个脚本重新排序,以便在导出数据时,最新的条目位于顶部?目前,它将最古老的数据放在首位。

function export_gcal_to_gsheet() {
var mycal = "Email";
var cal = CalendarApp.getCalendarById(mycal);
var events = cal.getEvents(new Date("July 01, 2022 00:00:00 UTC"), new Date ("September 12, 2022 23:59:59 UTC"));
var sheet = SpreadsheetApp.getActiveSheet();
sheet.clearContents();  
var header = [["Calendar Address", "Event Title", "Event Description", "Event Location", "Event Start", "Event End", "Calculated Duration", "Visibility", "Date Created", "Last Updated", "MyStatus", "Created By", "All Day Event", "Recurring Event"]]
var range = sheet.getRange(1, 1, 1, 14);
range.setValues(header);
for (var i = 0; i < events.length; i++) {
var row=i+2;
var myformula_placeholder = '';
var details=[[mycal,events[i].getTitle(), events[i].getDescription(), events[i].getLocation(), events[i].getStartTime(), events[i].getEndTime(), myformula_placeholder, ('' + events[i].getVisibility()), events[i].getDateCreated(), events[i].getLastUpdated(), events[i].getMyStatus(), events[i].getCreators(), events[i].isAllDayEvent(), events[i].isRecurringEvent()]];
var range=sheet.getRange(row,1,1,14);
range.setValues(details);
var cell=sheet.getRange(row,7);
cell.setFormula('=(HOUR(F' +row+ ')+(MINUTE(F' +row+ ')/60))-(HOUR(E' +row+ ')+(MINUTE(E' +row+ ')/60))');
cell.setNumberFormat('.00');
}
}

修改For循环中的公式

在for循环中,从以下位置修改行的公式:

var row=i+2;

至:

var row = events.length + 1 - i;

这将在行的顶部显示最近的条目。

相关内容

  • 没有找到相关文章

最新更新