使用 Apps 脚本缩短 googlesheets 中的 URL?

问题描述 投票:0回答:1

我有一个很长的网址,用于放入日历活动的谷歌幻灯片。一切正常,但长网址看起来很时髦,我希望能够使用谷歌表格可以自行生成的短网址,而不需要除 Apps 脚本之外的其他 API。 enter image description here

/*
* Calendar must be created in advance. 
* Once created go to Settings and scroll down to  Calender ID. 
* Copy and paste ID into <Calendar ID> cell of main worksheet
* Copy and paste the calendar name into <Calendar Name> cell of main worksheet
*/
function CreateManyEvents() {
//Retrieve information from the spreadsheet 
// Make the 3rd sheet active in the active spreadsheet.
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
SpreadsheetApp.setActiveSheet(spreadsheet.getSheets()[2]);

// Call function BulkDeleteEventsDelete on any pre-existing events 
BulkDeleteEvents(spreadsheet)

//Retrieve the value of the calendar ID from the cell that it lives in.
//Call CalendarApp service to open the calendar
var calendarId = spreadsheet.getRange("A1").getValue();
var eventCal = CalendarApp.getCalendarById(calendarId);

var classes = spreadsheet.getRange("A3:F8").getValues();
for (x=0; x<classes.length; x++) {   
    var item = classes[x];
    
    var title = item[0];
    var startTime = item[1];
    var endTime = item[2];
    var session = item[3];
    var what = item[5] + '\r\n\n' + item[4];

    //create event with data selected
    eventCal.createEvent(title, startTime, endTime,{location: session,description: what});  
    
  }

}

那么,在将 URL item[5] 与日历事件描述中的其他项目加入之前,有没有办法缩短它?

我环顾四周,解决方案都涉及更改我没有的工具中的设置 - 我所拥有的只是扩展下的 Apps 脚本 - 和/或使用一些第三方 API。

我希望有一个“内部”的解决方案。即使将 URL 更改为其 IP 地址也可以。

javascript google-apps-script
1个回答
0
投票

您可以尝试将 URL 嵌入到具有您喜欢的名称的

a
标记中,并将
item[5]
值放入 href 属性中。

截图

我已经尝试过了,看起来就是这样。

日历活动截图

代码示例

尝试在

description
键内添加 html,如下所示。

{description: "<a href='www.google.com'>Link</a>"});

让我知道这是否解决了问题,否则我可以找到其他东西。

© www.soinside.com 2019 - 2024. All rights reserved.