2016-07-07 182 views
0

我在Excel中有以下表格,其中col1 =電影ID,col2 =電影名稱。我正在嘗試使用Excel Web查詢來獲取列表中所有電影的製作公司名稱。使用excel查詢從URL中獲取xml數據的子串

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 

回答

0

問題解決了。這是我的解決方案。請注意,行號在此處是固定的,您可以將其更改爲動態。

此處列A包含具有唯一電影ID的所有網址。 例如

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