【问题标题】:Is it possible to display a Google sheet as HTML without revealing the URL of the sheet?是否可以在不显示工作表 URL 的情况下将 Google 工作表显示为 HTML?
【发布时间】:2021-01-13 23:01:53
【问题描述】:

我知道可以使用电子表格 ID 和 GID 将 Google 表格显示为 HTML,即:

https://docs.google.com/spreadsheets/d/SPREADSHEET_ID/gviz/tq?tqx=out:html&tq&gid=GID

但要查看它,您必须知道工作表的 URL。我想知道的是是否可以显示此 HTML 版本的工作表但不显示工作表的 URL?

【问题讨论】:

  • 我无法理解display this HTML version of the sheet but without revealing the URL of the sheet。我为此道歉。为了正确理解你的目标,我可以问你目标的细节吗?
  • 我希望能够在网页(即 HTML)中显示 Google 工作表,但不显示工作表的位置(这样就无法查看网页的来源并获取工作表的 URL)

标签: google-sheets


【解决方案1】:

手动

要检索 HTML 格式的电子表格,您可以通过单击 文件 -> 下载 -> 网页 将其导出。这将为您提供一个 zip 文件,其中包含您的电子表格的 HTML,您可以随意重命名,而无需透露电子表格 ID。

使用 Apps 脚本

您还可以自动执行此过程,创建一个 Apps 脚本函数,例如每次单击插入的按钮时都会触发该函数(为此,您只需单击菜单栏 插入 -> 绘图并在此按钮右上角的三个点上单击分配脚本并将其设置为您的函数名称)。

以下函数在运行时将在电子表格上显示一个模式对话框,如果用户单击Download,它将自动下载zip 文件,电子表格格式为HMTL。这个函数有不言自明的 cmets :

function downloadHTML() {
  // Get ID of the Spreadsheet
  var id = SpreadsheetApp.getActive().getId();
  // Get the download URL of this Spreadshet in format HTML on the background 
  var url = "https://docs.google.com/a/mydomain.org/spreadsheets/d/" + id + "/export?exportFormat=zip&access_token=" + ScriptApp.getOAuthToken();
  // Download when clicked on the button of the opened dialog
  var html = '<input type="button" value="Download" onClick="location.href=\'' + url + '\'" >';

  // create an HTML output from the given string
  var dialog = HtmlService.createHtmlOutput(html);

  // Show a modal dialog on the Spreadsheet UI when the function is run with the Title download
  SpreadsheetApp.getUi().showModalDialog(dialog, "Download");
}

参考

【讨论】:

  • 抱歉,我的意思是可以通过网络应用程序脚本或类似的方式以编程方式执行此操作吗?
  • 当然,您想要电子表格的特定工作表的 HTML 还是电子表格中的多个工作表的 HTML?您希望电子表格上的数据属于单独的页面,还是要将实际的电子表格嵌入 HTML 页面?
  • 可能只有一张纸(认为可能会改变),理想情况下数据显示在单独的页面上
猜你喜欢
  • 2016-12-07
  • 2013-07-24
  • 1970-01-01
  • 2013-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多