将 XML 列表映射到 Word 重复组件 (Word 2013)

Map an XML list into a Word repeating component (Word 2013)

我有一个从 excel 电子表格生成的 xml 文件。 xml 表示电子表格的行和列。

例如:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<data-set xmlns="dummy.xsd">
    <record>
        <LastName>Smith</LastName>
        <Sales>16753</Sales>
        <Country>UK</Country>
        <Quarter>Qtr 3</Quarter>
    </record>
    <record>
        <LastName>Johnson</LastName>
        <Sales>14808</Sales>
        <Country>USA</Country>
        <Quarter>Qtr 4</Quarter>
    </record>
    <record>
        <LastName>Williams</LastName>
        <Sales>10644</Sales>
        <Country>UK</Country>
        <Quarter>Qtr 2</Quarter>
    </record>
<data-set>

我希望能够遍历每一行并将其每个部分显示为一个单词组件,以便我可以使用单词格式对其进行格式化。

所以我会有类似的东西(使用 [[..]] 符号化组件和重复结构)

[[
    [[
        [[Lastname]]   -    [[Sales]] - [[Contry]] - [[Repeat]]
    ]]
    [[
        [[Lastname]]   -    [[Sales]] - [[Contry]] - [[Repeat]]
    ]]
]]

我已经打开了开发面板,并用(添加新部分...)[=37=加载我的xml ] XML 映射 窗格的功能。

当我右键单击 XML 层次结构的标签并执行 *Insert Content Control > Repeating" 时,这会创建一个包含以下文本的单词组件:

"Enter any content that you want to repeat, including other content controls. You can also insert this control around table rows in order to repeat parts of a table."

如果我在其中放入一些 record 字段,它 (Insert Content Control > PlainText) 显示为:

"Plain text controls cannot be inserted aroud the current selection"

我还尝试在 *Developer > Add-Ins > XML Schema > Add Schema 中放置一个模式

我的博客postword-2013-repeatingsection-content-controls-ready-for-prime-time 可能会感兴趣(包括 linked docx,其中包含一些 hints/learnings 映射窗格)

后面的 post i-have-my-xml-now-what 指向一个服务,该服务将从您的样本中生成重复结构 XML。

我终于做到了:

  1. 在"Ribbon"
  2. 中激活"Developer Pane"
  3. 打开"XML Mapping Pane"
  4. 选择"Developer > XML Mapping > Custom XML Part > Add new part (...)"和selectXML
  5. 然后 select 列表中的 XML 文件 "Custom XML Part" 和列表中的一个项目右击 select "Insert Content Control > Repeating" 这应该在文档
  6. 中创建一种"double tags"
  7. 然后,不要激活"Design Mode"("Developer > Design Mode")(否则它会报错)
    • 将鼠标光标放在页面中创建的 "double tags" 内(在 "Enter any content that you want to repeat, including other content controls. You can also insert this control around table rows in order to repeat parts of a table." 的位置)
    • 然后右键单击 "XML Mapping Pane" 中的项目字段并选择 "Insert content control > Plain text" 这将创建一个新的 "single tag" 代表单词页面中的字段(嵌套在代表 "foreach" 的 "double tag" 中)
    • 关闭设计模式(如果需要,再打开和关闭)。项目应显示并包含插入的字段

唯一的问题是它非常慢。我试图映射 100 行 XML(只有 2 列),花了将近 5 分钟。