是否可以在 google 个工作表中显示 iframe 或 webview

Is it possible to display an iframe or webview in google sheets

我有一个 google sheets 文件,其中只有产品的 URL。

我想在 sheet 中创建一些 iframe/webview/view,可以在该视图中加载 url 的内容。

例如当我 select 任何包含产品 url 的单元格时,webview/iframe 加载那个 url.

的内容

可能吗?

附上图片以供参考。

您可以使用 Google Apps Script 轻松实现它。

这些是要遵循的步骤:

  1. 在您的 sheet 中转到 Extensions>Apps Script
  2. 在 Code.gs 中,创建一个 onOpen(e) 函数,用于在用户打开表格时添加自定义菜单。
const onOpen = (e) => {
  SpreadsheetApp.getUi()
    .createMenu('Preview Content')
    .addItem('Show', 'previewProduct')
    .addToUi();
}
  1. 这会在用户点击菜单时触发一个函数。
  2. 正在创建函数previewProduct
const previewProduct = () => {
  /* Gets the actual user cell */
  /* You may want to implement some kind of control of what values */
  /* can be slected */
  /* ex. if(!value.match(urlRegex)) return */
  
  const range = SpreadsheetApp.getActiveRange()
  const value = range.getValue()
  if(value===null) return
  /* Fetchs the content and parse it as html */
  const html = UrlFetchApp.fetch(value).getAs('text/html')
  /* Creates an Output with the fetched HTML */
  /* You have two alternatives */
  /* Creating a Modal Dialog */
  const htmlOutput = HtmlService
    .createHtmlOutput(html)
    .setWidth(720)
    .setHeight(720);
  SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'My add-on');
  /* Creating a Sidebar */
  SpreadsheetApp.getUi().showSidebar(HtmlService.createHtmlOutput(html))
}
  1. 重新打开 Spreadsheet,将光标放在一个单元格中,然后单击 Preview Content > Show

文档