【发布时间】:2021-02-19 08:45:14
【问题描述】:
我有一个计算器,它可以在用户输入数量时运行顺畅,它会根据输入计算价格。
calculateQuantity(price) {
if (this.quantity <= 75) return 3.20;
if (this.quantity <= 100) return 2.72;
if (this.quantity <= 300) return 2.60;
if (this.quantity <= 500) return 2.58;
if (this.quantity >= 500) return 2.56;
}
calculate() {
subtotal = this.calculateQuantity(subtotal);
subtotal = subtotal * this.quantity;
this.subtotal = subtotal;
现在我需要链接一个每天都会更新的 Google 表格,以确定上述代码中的价格,但我不知所措。我已经浏览了 Google API,并且我已经将工作表显示在页面上,但不知道如何获取特定单元格并将其用作价格。
基本上我认为我想要的是类似的东西
if (this.quantity <= 75) return (ROW 1:COLUMN 1);
如果有人可以为我提供一些启示。我已经搜索了谷歌,我发现的大部分内容只是如何基本显示工作表,而不是如何获取特定数据,它是否在代码中。
也许有更好的解决方案,非技术客户可以轻松输入价格以获取,甚至 Excel 会更好。
【问题讨论】:
-
您可以使用 GET 请求从 Google 表格中读取值。详情请见developers.google.com/sheets/api/samples/reading。
-
关于
I've went through the google api and I've gotten the sheet to display on a page but cant figure out how to grab a specific cell and use it a the price.,可以问一下这个细节吗?而且,虽然我看到了你的脚本,但我找不到与此相关的脚本。我为此道歉。那么,您能否提供经过测试的脚本以使用 Google 电子表格? -
题外话:为什么函数上有
price参数,却从来没用过?
标签: javascript google-sheets google-sheets-api