Excel 中的 API 实现

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

我尝试导入 Excel 时遇到一些 API 问题。我将一列导入到 Excel,但另一列没有导入。

How the columns look on the website

我正在尝试从瑞典统计研究所导入它们。 SCB(链接不会直接转到指定的列,但可能会有一些用处)

使用Excel“数据”选项卡中的“来自网络”功能,使用此URL; https://api.scb.se/OV0104/v1/doris/sv/ssd/START/PR/PR0101/PR0101A/KPItotM

网站上还有一个JSON问题:

{
  "query": [
    {
      "code": "ContentsCode",
      "selection": {
          "filter": "item",
          "values": [ "000004VU" ]
      }
    },
    {
      "code": "Tid",
      "selection": {
          "filter": "item",
          "values": [ "1980M09", "1981M09", "1982M09", "1983M09", "1984M09",
                      "1985M09", "1986M09", "1987M09", "1988M09", "1989M09",
                      "1990M09", "1991M09", "1992M09", "1993M09", "1994M09",
                      "1995M09", "1996M09", "1997M09", "1998M09", "1999M09",
                      "2000M09", "2001M09", "2002M09", "2003M09", "2004M09",
                      "2005M09", "2006M09", "2007M09", "2008M09", "2009M09",
                      "2010M09", "2011M09", "2012M09", "2013M09", "2014M09",
                      "2015M09", "2016M09", "2017M09", "2018M09", "2019M09",
                      "2020M09", "2021M09", "2022M09", "2023M09", "2023M11" ]
      }
    }
  ],
  "response": {
    "format": "px"
  }
}

但我不知道如何在 Excel 中使用该文件,我尝试导入 JSON 文件但无济于事。我的理解是我不需要密码等。

How it looks in excel

预计两列都会被导入,但只得到了一列。

这是指南

json excel import
1个回答
0
投票

这里的代码似乎适用于您显示的请求。

将请求中的

Response
参数从“px”更改为“json”

我将请求存储在 Excel 的表格中,但如果您愿意,可以将其硬编码到查询中。

我建议您阅读代码注释并按照应用步骤更好地理解逻辑。

let
    url = "https://api.scb.se/OV0104/v1/doris/en/ssd/START/PR/PR0101/PR0101A/KPItotM",

//In your json formatted request, in the "response" paramater, change "px" to "json"
//I stored my request in an Excel table named `JSON Req` but you can put it anyplace
  
    jsonReq = Text.ToBinary(Excel.CurrentWorkbook(){[Name="jsonReq"]}[Content]{0}[JSON Req]),

//Note the web contents includes the request
    web = Web.Contents(url, [Content=jsonReq]),
  
    json =Json.Document(web),
  
//Extract and format the desired information
    #"Converted to Table" = Record.ToTable(json),
    #"Filtered Rows" = Table.SelectRows(#"Converted to Table", each ([Name] = "data")),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Name"}),

    #"Expanded Value" = Table.ExpandListColumn(#"Removed Columns", "Value"),
    #"Expanded Value1" = Table.ExpandRecordColumn(#"Expanded Value", "Value", {"key", "values"}, {"key", "values"}),
    
    #"Expanded key" = Table.ExpandListColumn(#"Expanded Value1", "key"),
    #"Expanded values" = Table.ExpandListColumn(#"Expanded key", "values"),
    
    #"Transform to Numbers" = Table.TransformColumns(#"Expanded values", {"values", each Number.From(_)}),
    #"Changed Type" = Table.TransformColumnTypes(#"Transform to Numbers",{{"key", type text}, {"values", Currency.Type}},"sv-SE")
in
    #"Changed Type"

您的请求的结果

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