Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从Google Drive电子表格单元格获取数据_Javascript_Html_Google Sheets_Spreadsheet_Google Drive Api - Fatal编程技术网

Javascript 从Google Drive电子表格单元格获取数据

Javascript 从Google Drive电子表格单元格获取数据,javascript,html,google-sheets,spreadsheet,google-drive-api,Javascript,Html,Google Sheets,Spreadsheet,Google Drive Api,我试图使用以下javascript代码显示来自Google Drive电子表格单元格的HTML文档中的一些数据: var URL = "https://docs.google.com/spreadsheet/pub?key=0AhQNAOBkQ63ldFl6N0tDeTFDYWVXeF8yQ0kwdWtoZnc&gid=0&single=true&gid=0&output=txt&range="; $.ajax(URL + "D2").done(funct

我试图使用以下javascript代码显示来自Google Drive电子表格单元格的HTML文档中的一些数据:

var URL = "https://docs.google.com/spreadsheet/pub?key=0AhQNAOBkQ63ldFl6N0tDeTFDYWVXeF8yQ0kwdWtoZnc&gid=0&single=true&gid=0&output=txt&range=";
$.ajax(URL + "D2").done(function(result){ document.getElementById("demo").innerHTML=result; });

当我有一个带有演示id的HTML标记时,这可以正常工作,但我需要将该值作为变量,这样我就可以在页面中的任何位置而不是特定的HTML元素中显示它。

您需要指定async:false,因为否则在尝试使用该变量之前,该变量可能无法设置。此外,出于某些范围的原因,在window ie window.variable的上下文中引用变量是最容易的


在我之前的信息中,我可能不够清楚。我需要创建多个javascript变量,这些变量的值来自不同的单元格。例如,var1=101.43;var2=12,依此类推。然后我就可以在不同的地方显示它们的值,而不用使用ID,只需使用document.writevar2;明白了,塞缪尔,我看到变量中的值了,谢谢!只是在Internet Explorer中检查了它,它没有显示从版本7到版本9的任何内容!有什么想法吗?我现在用Chrome不行了。。。如果您试图访问您提供的Google文档url,它会说单元格范围无效。所以这里有一个更深层次的问题,你可能需要自己解决。
var URL = "https://docs.google.com/spreadsheet/pub?key=0AhQNAOBkQ63ldFl6N0tDeTFDYWVXeF8yQ0kwdWtoZnc&gid=0&single=true&gid=0&output=txt&range=";

window.variable = "test";

$.ajax({url:URL + "D2",async:false}).done(function(result){ window.variable = result; });

document.getElementById("demo").innerHTML = window.variable;