如何从电子邮件导入谷歌工作表ID或链接



我每周都会收到一封电子邮件,每次生成一个新的电子表格都会有一个新的链接。我想要能够做的是有一个脚本自动拉在工作表ID到现有的工作表,以便数据可以导入。

下面是我收到的一封电子邮件的例子:


Good afternoon, 
Below is the link to the new Report for this week.    
New Report 08/02/21 https://docs.google.com/spreadsheets/d/1JFazdGz16kIJfjPsez-G6vLGKV9u5Vk3OpZAFelwPeo!!/edit?usp=sharing </LINK>
NOTE: The link to the Report will change every week. If you use a link from a previous email it will take you to that week's Report, not the current one.
Please download the file if you need to filter the report. 
Any schedule changes, terminations, and transfers that come in after the weekly Report has been processed will not be reflected in that week's Report. 
Thank you,

注意:我插入的标签在邮件中是不可见的。文本New Report是一个超链接,其链接与发布的链接相似。

所有我想提取的是链接本身或链接内的ID。都可以。

只需在字符串中搜索工作表地址参数,然后根据斜杠/截断结尾。

function findID(tText) {
const tangotText = "https://docs.google.com/spreadsheets/d/"
var theStart = tText.search(tangotText)+tangotText.length;
var newText = tText.slice(theStart,tText.length);
return newText.slice(0,newText.search("/"));
}

function testFunction(){
var result = findID("New Report 08/02/21 https://docs.google.com/spreadsheets/d/1JFazdGz16kIJfjPsez-G6vLGKV9u5Vk3OpZAFelwPeo!!/edit?usp=sharing </LINK>");
Logger.log(result);
}

最新更新