简体   繁体   English

将谷歌电子表格中的数据提取到 html 表中

[英]extracting data from google spreadsheet into a html table

I have a google spreadsheet that stores data at my work and is constantly being updated via google drive so it is always online editing, what I want to do is to be able to extract the values in those cells and have them show up in a HTML5 table on my website, what would be the best solution for this?我有一个谷歌电子表格,它在我的工作中存储数据,并且通过谷歌驱动器不断更新,所以它总是在线编辑,我想要做的是能够提取这些单元格中的值并让它们显示在 HTML5 中我网站上的表格,什么是最好的解决方案?

I did try one way which was to just embed the spreadsheet in a iFrame and have that refresh every 5 minutes, but the refresh loading is too slow and it causes issues with trying to get the spreadsheet to fit perfectly in the iframe everytime I refresh.我确实尝试了一种方法,即仅将电子表格嵌入 iFrame 并每 5 分钟刷新一次,但刷新加载速度太慢,并且每次刷新时尝试使电子表格完全适合 iframe 会导致问题。 these websites will be on display on TV screens so I dont want to be adjusting them regularly, they will auto refresh and be idle.这些网站将显示在电视屏幕上,所以我不想定期调整它们,它们会自动刷新并处于空闲状态。

Your Google Sheet's rows/columns can be exported as a pretty minimal HTML table.您的 Google Sheet 的行/列可以导出为一个非常小的 HTML 表格。 You can grab that HTML and manipulate it however you like.您可以抓取该 HTML 并随意操作它。 Here's how to get it:获取方法如下:

  1. Open the Sheet and find your file_id in the URL, and the gid for the specific tab you wish to export (you may have several spreadsheets within a single Google Sheet).打开表格并在 URL 中找到您的file_id ,以及您希望导出的特定标签的gid (您可能在一个 Google 表格中有多个电子表格)。

  2. Use this URL string, replacing <FILE_ID> and <TAB_GID> with your own:使用此 URL 字符串,将<FILE_ID><TAB_GID>替换为您自己的:

    • https://docs.google.com/spreadsheets/d/<FILE_ID>/gviz/tq?tqx=out:html&tq&gid=<TAB_GID>

You can set the refresh/recalculation rate under File > Spreadsheet settings to be every minute, if necessary.如有必要,您可以将文件 > 电子表格设置下的刷新/重新计算率设置为每分钟。


Example:例子:

Here is a Google Sheet with some data. 是一个包含一些数据的谷歌表。 To export this as an HTML table, we take:要将其导出为 HTML 表格,我们采用:

  • the file_id : 1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms and file_id : 1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms
  • the tab_gid : 0 tab_gid : 0

from the URL and substitute those into the URL string (above), yielding:从 URL 并将它们替换为 URL 字符串(如上),产生:

https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/gviz/tq?tqx=out:html&tq&gid=0 https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/gviz/tq?tqx=out:html&tq&gid=0


Hope that helps.希望有帮助。 🍻 🍻

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM