【问题标题】:Using excel query to get a substring of the xml data from a URL使用 excel 查询从 URL 获取 xml 数据的子字符串
【发布时间】:2016-07-07 16:54:44
【问题描述】:

我在 excel 中有下表,其中 col1=电影 ID,col2 = 电影名称。我正在尝试使用 excel 网络查询来获取列表中所有电影的制作公司名称。

ID          Movie Name
tt1540741   A Single Shot (2013)
tt4630158   A Space Program (2015 Documentary)

例如 http://www.omdbapi.com/?i=tt2330270&tomatoes=true&plot=short&r=xml

该链接将返回一个包含生产公司名称的 XML。

我不确定如何编写能够实现此目标的 excel 公式。

(我希望输出看起来像这样)

ID          Movie Name                         Production firm
tt1540741   A Single Shot (2013)                      ABC
tt4630158   A Space Program (2015 Documentary)        DEF

【问题讨论】:

    标签: excel excel-web-query


    【解决方案1】:

    问题解决了。这是我的解决方案。请注意,此处的行号是固定的,您可以将其更改为动态的。

    此处的 A 列包含具有唯一电影 ID 的所有 URL。 例如

    http://www.omdbapi.com/?i=tt0811137&tomatoes=true&plot=short&r=xml

    Sub getMovieInfo()
    '  Application.ScreenUpdating = False
      Dim x As Integer
      ' Set numrows = number of rows of data.
      NumRows = 1491
      ' Select cell a1.
      Range("A1").Select
      ' Establish "For" loop to loop "numrows" number of times.
      For x = 1 To 1491
         ' Insert your code here.
         pos = "A" & x
         des = "$D" & x
        ActiveWorkbook.XmlImport URL:=Cells.Item(x, "A"), _
        ImportMap:=Nothing, Overwrite:=True, Destination:=Sheets("Sheet3").Range(des)
       ' Sheets("Sheet1").Range(des).Value = Cells.Item(x, "A")
        Application.Wait (Now + TimeValue("00:00:2"))
    
        If (IsEmpty(Sheets("sheet3").Range(des)) = True) Then
        Application.Wait (Now + TimeValue("00:00:10"))
            If (IsEmpty(Sheets("sheet3").Range(des)) = True) Then
            Exit Sub
            End If
        End If
    
         ActiveCell.Offset(1, 0).Select
      Next
      End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-07
      • 1970-01-01
      • 2020-06-12
      • 2018-08-04
      • 1970-01-01
      • 2017-07-20
      相关资源
      最近更新 更多