【问题标题】:Extract data from multiple XMLs into a single Excel document (1 row per xml)将多个 XML 中的数据提取到单个 Excel 文档中(每个 xml 1 行)
【发布时间】:2015-06-05 20:29:56
【问题描述】:

我有 1000 多个 xml 文件,我需要遍历 xml 文件,选择指定的数据片段并将它们插入到单个 excel 文档中的每个文件的单个行中(每个 xml 文件 1 行)。

所有 xml 文件的格式如下...

<?xml version="1.0"?>
-<simpleXMLResult xmlns="http://sdk.prometric.com/schemas/SimpleXMLResults1_3" version="1.3">
-<demographics workstationname="T003" functioncode="41472" appointmentid="0000000076499080">
<demographic value="SHRMAPP860" name="ClientID"/>
<demographic value="USA" name="Country"/>
</demographics>
-<exam workstationname="T003" functioncode="41472" name="SCP" countmarked="0" countskipped="0" countincorrect="39" countcorrect="111" count="150" restartcount="0" duration="11006" enddatetime="2015-05-27T10:37:18" startdatetime="2015-05-27T07:33:51" driverversion="8.9.2 Build #0 (UTD 8.9 CORE (A))" examformname="Form4" resourceversion="2.0" resourcefilename="41472.cer">
<score scorecut="0" scoremax="150" scoremin="0" passindicator="p" scoredisplay="111.00" scorevalue="111"/>
-<sections>
<section name="scnConfirm" countmarked="0" countskipped="0" countincorrect="0" countcorrect="0" count="0" duration="34" enddatetime="2015-05-27T07:34:29" startdatetime="2015-05-27T07:33:52"/>
-<section name="scnNDA" countmarked="0" countskipped="0" countincorrect="0" countcorrect="0" count="0" duration="17" enddatetime="2015-05-27T07:34:49" startdatetime="2015-05-27T07:34:30">
-<itemgroup name="NDA.1" duration="17.691" visited="1" presented="1" weight="1" progid="UTDP.MultiChoiceItem.1" scored="0">
<item scoremax="1" scoremin="0" marked="0" skipped="0" complete="1" scorenom="0" score="1" correctresponse="A" response="A"/>
</itemgroup>
</section>
-<section name="scnForm4" countmarked="0" countskipped="0" countincorrect="39" countcorrect="111" count="150" duration="10260" enddatetime="2015-05-27T10:37:18" startdatetime="2015-05-27T07:41:36">
<score scorecut="0" scoremax="150" scoremin="0" passindicator="p" scoredisplay="111.00" scorevalue="111"/>
-<itemgroup name="F4_1" duration="87.11" visited="3" presented="1" weight="1" progid="UTDP.MultiChoiceItem.1" scored="1">
<item scoremax="1" scoremin="0" marked="0" skipped="0" complete="1" scorenom="0" score="1" correctresponse="C" response="C"/>
</itemgroup>
-<itemgroup name="F4_2" duration="19.796" visited="1" presented="1" weight="1" progid="UTDP.MultiChoiceItem.1" scored="1">
<item scoremax="1" scoremin="0" marked="0" skipped="0" complete="1" scorenom="0" score="1" correctresponse="C" response="C"/>
</itemgroup>
-<itemgroup name="F4_3" duration="28.314" visited="1" presented="1" weight="1" progid="UTDP.MultiChoiceItem.1" scored="1">
<item scoremax="1" scoremin="0" marked="0" skipped="0" complete="1" scorenom="0" score="0" correctresponse="D" response="B"/>
</itemgroup>
-<itemgroup name="F4_4" duration="45.724" visited="1" presented="1" weight="1" progid="UTDP.MultiChoiceItem.1" scored="1">
<item scoremax="1" scoremin="0" marked="0" skipped="0" complete="1" scorenom="0" score="1" correctresponse="D" response="D"/>
</itemgroup>
-<itemgroup name="F4_5" duration="35.772" visited="1" presented="1" weight="1" progid="UTDP.MultiChoiceItem.1" scored="1">
<item scoremax="1" scoremin="0" marked="0" skipped="0" complete="1" scorenom="0" score="1" correctresponse="D" response="D"/>
</itemgroup>
</section>
</exam>
</simpleXMLResult>

我希望每行的数据看起来像这样...由于我无法发布图片,我将尝试将其写出来。

A1 = <exam> name ("SCP")
B1 = <demographic> value where name = "ClientID" in this case ("SHRMAPP860")
C1 = <exam> examformname ("Form4")
* For the rest of the columns there could be a dynamic number
D1 = <item> response ("A") ** There could be 5 of these or 100 depending on the xml file, I need each one put into its own column
E1 = <item> response ("C")...
F1 = ""

我曾尝试使用 Excel 中内置的 XML 映射,但它似乎并不现实,因为我有超过 1000 个 xml 文件,并且在尝试获取我需要的数据格式时很挑剔。我有一些 VBA 经验并且之前写过宏.我的主要问题是如何从所有 xml 文件中获取数据并转换为我可以使用的工作表单。 你们认为实现这一目标的最佳方法是什么?

【问题讨论】:

  • 也许这应该是一个维基问题
  • 我对堆栈溢出仍然很陌生 什么是 wiki 问题以及如何将我的问题合二为一?

标签: xml excel extract


【解决方案1】:

我使用 PHPexcel 在非常复杂和不可预测的 Excel 表中取得了令人敬畏的结果。这是一个非常简单的 api,您可以在很短的时间内获得强大的结果。

文档链接: https://github.com/PHPOffice/PHPExcel/wiki/User%20Documentation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-20
    • 2021-09-09
    • 1970-01-01
    相关资源
    最近更新 更多