简体   繁体   English

简单的Javascript代码可显示Google电子表格中单个字段中的数据

[英]SIMPLE Javascript code to display data from a single field in a Google Spreadsheet

First off, I am NOT a professional programmer, which is why I am here for help, so thanks in advance for your time and patience. 首先,我不是专业程序员,这就是为什么我在这里寻求帮助,所以在此先感谢您的时间和耐心。 I need a bit of code for a website that will call and display information from a specific field in a published Google spreadsheet, to be displayed via HTML, through javascript or some other similar method. 我需要一个网站代码,该网站将调用并显示已发布的Google电子表格中特定字段的信息,并通过HTML,JavaScript或其他类似方法显示。

Looking around, there seems to be several ways of doing this, but all of the examples and tricks I can find are a bit beyond my expertise, and my efforts at applying several of those methods have, frankly, failed miserably. 环顾四周,似乎有几种方法可以做到这一点,但是我可以找到的所有示例和技巧都超出了我的专业知识,坦率地说,我在应用这些方法中的几种方法都失败了。 I have searched through previous questions, but they all cite examples that are way more complicated than what I need. 我已经搜索了先前的问题,但是它们都引用了比我需要的示例更加复杂的示例。

If someone could cite me an easy example, I'd greatly appreciate it. 如果有人可以举一个简单的例子,我将不胜感激。 (The simpler the better.) In the meanwhile, I will continue to experiment to see what I can do. (越简单越好。)与此同时,我将继续尝试看看自己能做什么。

This is a duplicate of How can I access Google Sheet spreadsheets only with Javascript? 这与“ 如何仅使用Javascript访问Google表格电子表格”重复

But since that example is not trivial for beginners, here is the code that will show the second cell of the spreadsheet using the code from the answer above 但是,由于该示例对于初学者而言并不简单,因此以下代码将使用上面答案中的代码显示电子表格的第二个单元格

  1. Go to https://github.com/mikeymckay/google-spreadsheet-javascript and download the file google-spreadsheet.js 转到https://github.com/mikeymckay/google-spreadsheet-javascript并下载文件google-spreadsheet.js
  2. Edit that file with a text editor and change 使用文本编辑器编辑该文件并进行更改
    • this.jsonCellsUrl = "http:// to this.jsonCellsUrl = "// and this.jsonCellsUrl = "http://this.jsonCellsUrl = "//
    • this.jsonListUrl = "http:// to this.jsonListUrl = "// to not have mixed http and https in your page this.jsonListUrl = "http://this.jsonListUrl = "//在页面中没有混合使用http和https
  3. Change the var url in the below to point your sheet 更改下面的var网址以指向工作表

FIDDLE 小提琴

<!DOCTYPE html>
<html>
<head>
<title>Spreadsheet example</title>
<script type='text/javascript' src='//code.jquery.com/jquery-1.11.0.js'></script>
<script type='text/javascript' src='google-spreadsheet.js'></script>
<script type='text/javascript'>  
$(function() {

  var url = "https://spreadsheets.google.com/pub?key=0Ago31JQPZxZrdHF2bWNjcTJFLXJ6UUM5SldEakdEaXc&hl=en&output=html";

  var googleSpreadsheet = new GoogleSpreadsheet();
  googleSpreadsheet.url(url);
  googleSpreadsheet.load(function(result) {
    $('#results').html(result.data[1]); // show the 2nd (0-based) cell
  });
});
</script>
</head>
<body>
Here is the result: <span id="results"></span>
</body>
</html>

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

相关问题 有没有办法将私人谷歌电子表格中的数据显示为网站上的图表? - Is there a way to display data from a private google spreadsheet as a chart on a website? 使用Javascript和HTML从Google电子表格填充html代码 - Populate html code from Google Spreadsheet using Javascript and HTML 如何使用 JavaScript 将数据从 HTML 表单发送到 Google 电子表格? - How to send data from HTML form to Google Spreadsheet using JavaScript? 如何从JavaScript中的私人Google电子表格中读取数据-2014年11月? - How to read data from a private google spreadsheet in javascript — Nov 2014? 需要从谷歌电子表格获取数据到javascript以绑定到按钮 - Need to get data from google spreadsheet to javascript to tie to button 如何从 Google Spreadsheet 获取数据到 HTML 作为 javascript 变量? - How to get data from Google Spreadsheet to HTML as a javascript variable? 如何从 Google Spreadsheet 检索数据到 Javascript 或 JSON? - How to retrieve data from Google Spreadsheet to Javascript or JSON? 从Google Spreadsheet收集数据? - Harvest data from Google Spreadsheet? 使用Highcharts库显示Google电子表格数据 - Display Google spreadsheet data using Highcharts library Javascript从电子表格读取数据 - Javascript Read data from spreadsheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM