简体   繁体   English

将Google表格单元格数据导入简单的HTML元素

[英]Import Google Sheets cell data into simple HTML elements

First post here. 在这里的第一篇文章。

I'm looking to import cell data from Google Sheets into HTML elements. 我想将单元格数据从Google表格导入到HTML元素中。 An example would be having a Google Sheet with item pricing where I could push the individual cell data into an HTML element. 一个示例是使用商品定价的Google表格,其中我可以将单个单元格数据推送到HTML元素中。

I found these posts and it's what I'm looking for but I don't see a clear answer but it's most likely my lack of knowledge. 我找到了这些帖子,这就是我想要的,但是我没有找到明确的答案,但这很可能是我缺乏知识。 If someone could point me in the right direction that would be great. 如果有人可以指出正确的方向,那将是很好的。 I'm not asking for a tutorial, just an expert's opinion so I don't end up researching something thats incorrect and waste a lot of time. 我不是要教程,只是专家的意见,所以我不会最终研究不正确的东西并浪费很多时间。

Thank You. 谢谢。

Pull data from a google sheet and display as simple html text 从Google工作表中提取数据并显示为简单的html文本

RSSHow can I pull just ONE cell of data at a time for Google Sheets to embed into my HTML content? RSS我如何一次只提取一个单元格的数据以将Google表格嵌入到我的HTML内容中?

If you're going to use Sheets API then here's what it may look like. 如果您要使用Sheets API,则可能是这样。

I'll just give you a snippet to show this is doable. 我只给您一个片段,以证明这是可行的。

在此处输入图片说明

First fetch the data from the spreadsheet using the Reading a single range guide . 首先使用“ 读取单个范围”指南从电子表格中获取数据。

GET https://sheets.googleapis.com/v4/spreadsheets/spreadsheet_id/values/range 

which I used in my XMLHttpRequest: 我在XMLHttpRequest中使用的:

function fetchValues(){
         console.log("-----checkIfEmpty-----");
         var xhr = new XMLHttpRequest();
         xhr.open('GET', 'https://sheets.googleapis.com/v4/spreadsheets/'+myspreadsheetId+'/values/'+"Sheet1!"+A+":"+Z);
         xhr.setRequestHeader('Authorization', 'Bearer ' + myAccessToken);

          var arrayBuffer;
          var myArr;

         xhr.onload = function (oEvent) {
             arrayBuffer = xhr.response; // Note: not oReq.responseText
             console.log("arrayBuffer "+ arrayBuffer);
             myArr = JSON.parse(arrayBuffer);

              for(var i = 0; i <= myArr.values.length; i++){
                      document.write(myArr.values[0][i] + "   ");
              }
         };
         xhr.send(null);
      }

Print it on the html page using document.write . 使用document.write将其打印在html页面上。 I know this is a shabby job and there are proper ways of displaying data on the html page but I just wanted to show it's doable- from spreadhsheet to HTML page. 我知道这是一项简陋的工作,并且有在HTML页面上显示数据的正确方法,但我只是想表明它是可行的-从电子表格到HTML页面。

在此处输入图片说明

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

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