从谷歌文档电子表格获取单元格的价值到JavaScript [英] Getting value of a cell from google docs spreadsheet into javascript
问题描述
我有一个javascript函数
$ p $ function calculate(){
var interestRate = 4.5;
...
}
我想让interestRate来自单元格在谷歌文档电子表格。
我创建了Google文档电子表格,并将利率存储在单元格B2中我使用Google文档中的获取发布数据的链接功能获得一个链接到单元格B2。链接看起来像这样。
https://docs.google.com/spreadsheet/pub?key=....c&single=true&gid=0&range=b2&output = html
是否有从链接中获取值到我的JavaScript函数?
感谢
首先,我建议将获取已发布数据的链接作为csv,因为它只是1场,所以你不必解析它。
如果制作了此电子表格,并制作一份< a href =https://docs.google.com/spreadsheet/pub?key=0Auwt3KepmdoudE1iZFVFYmlQclcxbW85YzNZSTYyUHc&single=true&gid=0&range=b5&output=csv =nofollow>链接到获取链接发布数据,这个第二个链接在这种情况下只会得到一个csv。
你可以用下面的js代码来获得它(注意我使用的是jQuery)
$ $ p $ $ $ $ $ $ $ $ ajax(https://docs.google.com/spreadsheet/pub?key=0Auwt3KepmdoudE1iZFVFYmlQclcxbW85YzNZSTYyUHc&single=true&gid=0&range=b5&output=csv).done(function(result){
alert(result);
});
问候
编辑: 完整代码
<!doctype>
< html>
< head>
< script src =http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js> < /脚本>
< / head>
< body>
< script>
$ .ajax(https://docs.google.com/spreadsheet/pub?key=0Auwt3KepmdoudE1iZFVFYmlQclcxbW85YzNZSTYyUHc&single=true&gid=0&range=b5&output=csv).done(函数(result ){
alert(result);
});
< / script>
< / body>
< / html>
I have a javascript function
function calculate() {
var interestRate=4.5;
...
}
I would like the interestRate to come from a cell in a google Docs spreadsheet. I created a google docs spreadsheet, and stored the interest rate in Cell B2
I used the "Get a link to Published Data" feature in Google Docs to to get a link to cell B2. The link looks like this.
https://docs.google.com/spreadsheet/pub?key=....c&single=true&gid=0&range=b2&output=html
Is there anyway of getting the value from the link into my javascript function?
Thanks
First of all, what i would recommend is to "Get a link to Published Data" as csv, as it is just 1 field so you don't have to parse it. If made this spreadsheet, and make a link with "Get a link to Published Data", this second link will get a csv with just one field in this case. You will be able to get this with the following js code (note i'm using jQuery)
$.ajax("https://docs.google.com/spreadsheet/pub?key=0Auwt3KepmdoudE1iZFVFYmlQclcxbW85YzNZSTYyUHc&single=true&gid=0&range=b5&output=csv").done(function(result){
alert(result);
});
Regards
EDIT: The full code
<!doctype>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"> </script>
</head>
<body>
<script>
$.ajax("https://docs.google.com/spreadsheet/pub?key=0Auwt3KepmdoudE1iZFVFYmlQclcxbW85YzNZSTYyUHc&single=true&gid=0&range=b5&output=csv").done(function(result){
alert(result);
});
</script>
</body>
</html>
这篇关于从谷歌文档电子表格获取单元格的价值到JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!