我应该使用什么脚本来绕过谷歌电子表格中导入数据的限制

What script should I use to get around the restriction of ImportData in Google spreadsheet?

本文关键字:导入 电子表格 数据 谷歌 什么 脚本 本来 我应该      更新时间:2023-09-26

我有A列,其中包含某些互联网站点的URL页面。在 B 列中,我使用以下函数:

"=CONCATENATE(ImportData(URL from column A)"。

。以将数据页提取为此列中的文本,但 Google 文档对文档中的 50 个函数对此功能有限制。

换句话说,每次更改 A 列中的 URL 地址,如何在 B 列中以文本的形式提取网页的数据,就像我使用 ImportData 一样?

谢谢。

您可以使用 onOpen 触发器,该触发器对 A 列中的每个网址使用 UrlFetch,并在 B 列中设置文本。这将在每次打开电子表格时更新电子表格。

这可能会起作用(我以前从未使用过 UrlFetch):

 function onOpen(e){
  var sheet = SpreadsheetApp.getActiveSheet();
  //Load all the URLs
  var urls = sheet.getRange("A:A").getValues();
  //Initialize array for content
  var text = [];
  //Loop through URLs
  for(var i = 0; i < urls.length; i += 1){
    if(urls[i][0] === "") continue;//Skip blank cells
    //Fetch the webpage, push the content to the array (inside an array since it needs to be 2d)
    text.push(
      [UrlFetchApp.fetch(urls[i][0]).getContentText()]
    );
  }
  //Store text in spreadsheet in range the size of the text array
  sheet.getRange("B1:B" + text.length).setValues(text);
}

如果要在 url 更改时加载新内容,请使用 onEdit 触发器

function onEdit(e){
  //Get the active cell
  //Then get its url
  //Fetch the web page and store it in the cell next to edited url
}