convert xml to xls

2019-08-12 23:48发布

I'm looking for ideas on how to implement a way to get web based XML data into a spreadsheet. The ideal solution would update the spreadsheet every time it's opened with little or no user interaction (.i.e, I'd prefer to not have to tell people to run a macro).

however, my first thought (and probably what I'll end up going with) is a Perl script that downloads the XML, parses it, and spits out a spreadsheet - this won't update the spreadsheet and I'll have to generate the document on some type of schedule (yes, i prefer complete automation and coding myself out of jobs :) ). what i (think i) want is odbc for XML that would accept a URI, that would probably be ideal. this way, maybe i could map the XPath to columns and the spreadsheet would update automagically every time it was opened. or, maybe there's a way in VBA to get a URI and parse XML and have it run when the workbook is opened?

标签: xml excel vba xls
2条回答
成全新的幸福
2楼-- · 2019-08-13 00:12

Where is the xml file? is this location fix?

If yes, you can create a dataconnection in Excel to this xml file.

Then setup the xml connection to refresh when the excel file opens.

查看更多
家丑人穷心不美
3楼-- · 2019-08-13 00:20

Parse the XML file using DOM, then spit out the relevant values onto your sheet. Here's a trivial working example to get you started:

Dim d As DOMDocument
Dim n As IXMLDOMNode
Dim s As String

Set d = New DOMDocument
d.async = False 
d.Load "http://www.democracynow.org/podcast-video.xml" ' or "C:\myfile.xml"

Set n = d.SelectSingleNode("//channel/description")
s = n.Text
Range("A1") = s

This early binding requires a reference set as follows: Tools > References... > Microsoft XML

Note that d.async = False forces the load to complete before proceeding further; this is especially important when loading remote files.

You want to

update the spreadsheet every time it's opened with little or no user interaction (ie, i'd prefer to not have to tell people to run a macro)."

Then put the macro in the Workbook_Open event! That's what it's there for.

查看更多
登录 后发表回答