如何从公共谷歌电子表格中检索简单的xml

问题描述 投票:1回答:1

我正在使用arduino设备,我需要从谷歌电子表格中检索公共数据。

到目前为止,我已经发布了电子表格,我可以在https://spreadsheets.google.com/feeds/cells/1uphj-Oq3Xt6ImHJdezAUEX4u41_w1NNMlZU4Flr6lc4/1/public/full?range=a11:c12上访问它,可以在浏览器或arduino中打开它(我正在使用SIM800模块,因此它可以使用HTTPS而不会出现问题)。

这个输出是xml项目(我不是很喜欢XML):

<entry>
<id>https://spreadsheets.google.com/feeds/cells/1uphj-Oq3Xt6ImHJdezAUEX4u41_w1NNMlZU4Flr6lc4/1/public/full/R12C11</id>
<updated>2018-04-30T05:31:51.590Z</updated>
<category scheme='http://schemas.google.com/spreadsheets/2006' term='http://schemas.google.com/spreadsheets/2006#cell'/>
<title type='text'>K12</title>
<content type='text'>12345</content>
<link rel='self' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/cells/1uphj-Oq3Xt6ImHJdezAUEX4u41_w1NNMlZU4Flr6lc4/1/public/full/R12C11'/>
<gs:cell row='12' col='11' inputValue='12345' numericValue='12345.0'>12345</gs:cell>

其中一个请求的每个单元格。问题是,在这里我可以看到太多不需要/冗余的信息,例如,在“标题”和“内容”中我获得与“gs:cell”中相同的信息,“updated”实际上可能是有用的但是“链接”而“类别”对我来说是完全一次性的。

由于我将使用arduino和sim800模块(无法处理高数据传输速度),因此尽可能简单。

可能有一种方法可以在HTTP调用中请求简化,可能会添加一些参数或将“full”更改为其他内容。

任何帮助将不胜感激

google-sheets google-spreadsheet-api
1个回答
1
投票

您想要从电子表格ID range=a11:c121uphj-Oq3Xt6ImHJdezAUEX4u41_w1NNMlZU4Flr6lc4中检索更简单的响应。如果我的理解是正确的,那么如何使用查询语言检索值?我认为可能有几种方法。所以请把它想象成其中之一。

模式1:以HTML格式检索响应

https://docs.google.com/spreadsheets/d/1uphj-Oq3Xt6ImHJdezAUEX4u41_w1NNMlZU4Flr6lc4/gviz/tq?range=a11:c12&tqx=out:html

Result :

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>A11:C12</title>
</head>
<body>
<table border="1" cellpadding="2" cellspacing="0">
<tr style="font-weight: bold; background-color: #aaa;">
<td></td><td></td><td></td>
</tr>
<tr style="background-color: #f0f0f0">
<td>DataInCellA11</td><td>DataInCellB11</td><td>DataInCellC11</td>
</tr>
<tr style="background-color: #ffffff">
<td>DataInCellA12</td><td>DataInCellB12</td><td>DataInCellC12</td>
</tr>
</table>
</body>
</html>

模式2:以CSV格式检索响应

https://docs.google.com/spreadsheets/d/1uphj-Oq3Xt6ImHJdezAUEX4u41_w1NNMlZU4Flr6lc4/gviz/tq?range=a11:c12&tqx=out:csv

Result :

"DataInCellA11","DataInCellB11","DataInCellC11"
"DataInCellA12","DataInCellB12","DataInCellC12"

注意 :

  • 在这种情况下,无法以xml格式检索响应。没有tqx=out:xml
  • 作为示例,您可以使用上面的URL中的curl和浏览器检索值。
  • 如果要从其他工作表中检索值,请使用gid的查询。在此示例中,省略了gid=od6,即第一张纸。

参考:

如果我误解你的问题,我很抱歉。

© www.soinside.com 2019 - 2024. All rights reserved.