PowerQuery (M) 钻取 Google Sheets API v.3 并提取 sheet 名称和 link url
PowerQuery (M) to drill into Google Sheets API v.3 and extract sheet name and link url
所以我正在针对 Google Sheets API 的 v.3 进行编程(我知道我需要在某个时候移动到 v.4 但我正在隐藏给定的代码库。)我有一些代码来解析 JSON 并在代码中逐步钻取,但我也在尝试学习 PowerQuery 的 M 语言,所以我想再次获得有关如何编写此 PowerQuery 的帮助。
我已经把 JSON 整理到最小了,这里是
{ ""feed"": {""entry"": [
{ ""title"": { ""$t"": ""1 Med"" }, ""link"": [ { ""href"":
""https//removed1...."" } ] },
{ ""title"": { ""$t"": ""2 Dent"" }, ""link"": [ { ""href"":
""https//removed2...."" } ] },
{ ""title"": { ""$t"": ""3 Vet"" }, ""link"": [ { ""href"":
""https//removed3...."" }] }
] } }
JSON 模仿(在骨架基础上)来自 Google Sheets API v.3 的内容。所以我知道我需要通过提要和入口节点向下钻取以获得 sheet 的列表。 sheet名称位于 feed.entry[x].title.$t
,而 sheet 数据的 url 位于 feed.entry[x].link[y].href
,其中 x 递增,y 为 0。
我想查询 return,在本例中是一个 3 行 2 列的矩阵,sheetname 在左列,href 在右列。于是
'1 Med' 'https//removed1'
'2 Dent' 'https//removed2'
'3 Vet' 'https//removed3'
到目前为止,我已经了解了下面的内容,但我现在卡住了。
let
Source = Json.Document("{ ""feed"": {""entry"": [
{ ""title"": { ""$t"": ""1 Med"" }, ""link"": [ { ""href"": ""https//removed1...."" } ] },
{ ""title"": { ""$t"": ""2 Dent"" }, ""link"": [ { ""href"": ""https//removed2...."" } ] },
{ ""title"": { ""$t"": ""3 Vet"" }, ""link"": [ { ""href"": ""https//removed3...."" }] }
] } }"),
feed = Source[feed],
entry = feed[entry],
#"Converted to Table" = Table.FromList(entry, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"title"}, {"title"})
in
#"Expanded Column1"
如果有足够多的例子,我会在一本食谱中掌握其中的诀窍,就像我被困住了一样。谢谢。
我非常好奇您将如何克服身份验证挑战。在我看来 "mission impossible" ...
无论如何,我在 GUI 中玩过你的脚本,删除了最后一步,又添加了一些,我想这就是你想要的:
let
Source = Json.Document("{ ""feed"": {""entry"": [
{ ""title"": { ""$t"": ""1 Med"" }, ""link"": [ { ""href"": ""https//removed1...."" } ] },
{ ""title"": { ""$t"": ""2 Dent"" }, ""link"": [ { ""href"": ""https//removed2...."" } ] },
{ ""title"": { ""$t"": ""3 Vet"" }, ""link"": [ { ""href"": ""https//removed3...."" }] }
] } }"),
feed = Source[feed],
entry = feed[entry],
#"Converted to Table" = Table.FromList(entry, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column2" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"title", "link"}, {"title", "link"}),
#"Expanded title1" = Table.ExpandRecordColumn(#"Expanded Column2", "title", {"$t"}, {"$t"}),
#"Expanded link" = Table.ExpandListColumn(#"Expanded title1", "link"),
#"Expanded link1" = Table.ExpandRecordColumn(#"Expanded link", "link", {"href"}, {"href"})
in
#"Expanded link1"
所以我正在针对 Google Sheets API 的 v.3 进行编程(我知道我需要在某个时候移动到 v.4 但我正在隐藏给定的代码库。)我有一些代码来解析 JSON 并在代码中逐步钻取,但我也在尝试学习 PowerQuery 的 M 语言,所以我想再次获得有关如何编写此 PowerQuery 的帮助。
我已经把 JSON 整理到最小了,这里是
{ ""feed"": {""entry"": [
{ ""title"": { ""$t"": ""1 Med"" }, ""link"": [ { ""href"":
""https//removed1...."" } ] },
{ ""title"": { ""$t"": ""2 Dent"" }, ""link"": [ { ""href"":
""https//removed2...."" } ] },
{ ""title"": { ""$t"": ""3 Vet"" }, ""link"": [ { ""href"":
""https//removed3...."" }] }
] } }
JSON 模仿(在骨架基础上)来自 Google Sheets API v.3 的内容。所以我知道我需要通过提要和入口节点向下钻取以获得 sheet 的列表。 sheet名称位于 feed.entry[x].title.$t
,而 sheet 数据的 url 位于 feed.entry[x].link[y].href
,其中 x 递增,y 为 0。
我想查询 return,在本例中是一个 3 行 2 列的矩阵,sheetname 在左列,href 在右列。于是
'1 Med' 'https//removed1'
'2 Dent' 'https//removed2'
'3 Vet' 'https//removed3'
到目前为止,我已经了解了下面的内容,但我现在卡住了。
let
Source = Json.Document("{ ""feed"": {""entry"": [
{ ""title"": { ""$t"": ""1 Med"" }, ""link"": [ { ""href"": ""https//removed1...."" } ] },
{ ""title"": { ""$t"": ""2 Dent"" }, ""link"": [ { ""href"": ""https//removed2...."" } ] },
{ ""title"": { ""$t"": ""3 Vet"" }, ""link"": [ { ""href"": ""https//removed3...."" }] }
] } }"),
feed = Source[feed],
entry = feed[entry],
#"Converted to Table" = Table.FromList(entry, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"title"}, {"title"})
in
#"Expanded Column1"
如果有足够多的例子,我会在一本食谱中掌握其中的诀窍,就像我被困住了一样。谢谢。
我非常好奇您将如何克服身份验证挑战。在我看来 "mission impossible" ...
无论如何,我在 GUI 中玩过你的脚本,删除了最后一步,又添加了一些,我想这就是你想要的:
let
Source = Json.Document("{ ""feed"": {""entry"": [
{ ""title"": { ""$t"": ""1 Med"" }, ""link"": [ { ""href"": ""https//removed1...."" } ] },
{ ""title"": { ""$t"": ""2 Dent"" }, ""link"": [ { ""href"": ""https//removed2...."" } ] },
{ ""title"": { ""$t"": ""3 Vet"" }, ""link"": [ { ""href"": ""https//removed3...."" }] }
] } }"),
feed = Source[feed],
entry = feed[entry],
#"Converted to Table" = Table.FromList(entry, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column2" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"title", "link"}, {"title", "link"}),
#"Expanded title1" = Table.ExpandRecordColumn(#"Expanded Column2", "title", {"$t"}, {"$t"}),
#"Expanded link" = Table.ExpandListColumn(#"Expanded title1", "link"),
#"Expanded link1" = Table.ExpandRecordColumn(#"Expanded link", "link", {"href"}, {"href"})
in
#"Expanded link1"