简体   繁体   English

Excel VBA-从网页表导入数据

[英]Excel VBA - Importing Data from a Webpage Table

The site http://api.eve-central.com/api/marketstat?typeid=34&usesystem=30000142 allows developers to pull data from their site in a format such as below: 网站http://api.eve-central.com/api/marketstat?typeid=34&usesystem=30000142允许开发人员以如下格式从其网站提取数据:

<evec_api version="2.0" method="marketstat_xml">
    <marketstat>
        <type id="34">
            <buy>
                <volume>22949619736</volume>
                <avg>4.61</avg>
                <max>4.76</max>
                <min>1.72</min>
                <stddev>0.64</stddev>
                <median>4.66</median>
                <percentile>4.75</percentile>
            </buy>
            <sell>
                <volume>18253017309</volume>
                <avg>6.01</avg>
                <max>11.87</max>
                <min>4.79</min>
                <stddev>1.23</stddev>
                <median>6.09</median>
                <percentile>4.81</percentile>
            </sell>
            <all>
                <volume>41214748156</volume>
                <avg>5.23</avg>
                <max>11.87</max>
                <min>0.26</min>
                <stddev>1.32</stddev>
                <median>4.75</median>
                <percentile>4.31</percentile>
            </all>
        </type>
    </marketstat>
</evec_api>

If I use the "Microsoft Excel 2010" -> "Data" -> "From Web" wizard then everything is formatted in a way that is easy to use, but I want to Query the results using a "For Each" loop in VBA. 如果我使用“ Microsoft Excel 2010”->“数据”->“从Web”向导,则所有内容的格式都易于使用,但我想使用VBA中的“ For Each”循环查询结果。 I tried using this to test a single result: 我尝试使用它来测试单个结果:

Sub URL_Static_Query()
    Set QT = ActiveSheet.QueryTables.Add(Connection:= _
    "URL;http://api.eve-central.com/api/marketstat?typeid=34&usesystem=30000142", _
    Destination:=Range("A1"))
    With QT
        .EnableEditing = False
        .BackgroundQuery = True
        .Refresh BackgroundQuery:=False
        .SaveData = False
    End With
End Sub

When I call this function it is formatted in a much different way than using the wizard. 当我调用此函数时,其格式与使用向导的格式大不相同。 It makes it much more difficult to handle the information, especially when querying from several different webpages on the same sheet. 这使处理信息变得更加困难,尤其是在同一张纸上从多个不同的网页进行查询时。

My main goal is to only pull the buy and sell results without any column or row headers; 我的主要目标是仅获取买卖结果,而没有任何列或行标题。 those I can enter in manually. 我可以手动输入的那些 Any help will be greatly appreciated, thanks! 任何帮助将不胜感激,谢谢!

After hours and hours of searching I finally found the answer to my question from http://www.mrexcel.com/forum/excel-questions/697000-importing-web-xml-data.html . 经过数小时的搜索,我终于从http://www.mrexcel.com/forum/excel-questions/697000-importing-web-xml-data.html找到了我的问题的答案。

The code is: 代码是:

 ActiveWorkbook.XmlImport URL:= _
        "http://api.eve-central.com/api/marketstat?typeid=34&usesystem=30000142", _                            
        ImportMap:=Nothing, _
        Overwrite:=True, Destination:=Range("$A$1")

Thank you chis neilsen for your suggestion! 谢谢chis neilsen的建议! It did help me eventually find what I needed. 它确实帮助我最终找到了我需要的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM