Word XML包括图片'手动'插入媒体文件夹

时间:2018-02-15 04:00:36

标签: xml

背景故事:我正在编写一个dxl(IBM Rational DOORS)脚本,它将模块的内容导出到xml,这些xml部分介于文档标记之间。将标题和文本转换为xml文本的部分功能完美。我的任务是添加图像导出器。我把所有内容都放在了,除了实际上让图像正确显示。

我星期三上周第一次遇到了xml,所以我可以做一些指针和手部故障排除。

问题:我正处于运行脚本的阶段,当我将更新的document.xml移回单词.zip文件时(然后将扩展名更改回.docx) ),我最终得到一个大的白色方形告诉我"此图像目前无法显示"。

it's times like these of minor annoyance and setback that I would like to pick an easier career.

流程:

  1. 我将.docx更改为.zip并打开zip文件夹。
  2. 在/ word / media子文件夹中,我插入带有名称的新图像 例如Image6.jpeg(鉴于此前有5张图片)
  3. 我在想要图片发生的部分更新xml, 以下代码:

            <w:p w:rsidR="00465B0A" w:rsidRDefault="00C35F8C">
              <w:r>
                <w:rPr>
                  <w:noProof/>
                  <w:lang w:eastAsia="en-AU"/>
                </w:rPr>
              <w:drawing>
                <wp:inline distT="0" distB="0" distL="0" distR="0">
                <wp:extent cx="5720080" cy="3221355"/>
                <wp:effectExtent l="0" t="0" r="0" b="0"/>
                <wp:docPr id=picCount  name="Picture " picCount " descr="inserted picture"/>
                  <wp:cNvGraphicFramePr>
                    <a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" noChangeAspect="1"/>
                  </wp:cNvGraphicFramePr>
                  <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                    <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
                      <pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">
                        <pic:nvPicPr>
                          <pic:cNvPr id=picCount name="Picture " picCountU descr="inserted picture"/>
                            <pic:cNvPicPr>
                              <a:picLocks noChangeAspect="1" noChangeArrowheads="1"/>
                            </pic:cNvPicPr>
                          </pic:nvPicPr>
                          <pic:blipFill>
                            <a:blip r:embed="rId"picCountU cstate="print"/>
                            <a:srcRect/>
                            <a:stretch>
                              <a:fillRect/>
                            </a:stretch>
                          </pic:blipFill>
                          <pic:spPr bwMode="auto">
                            <a:xfrm>
                              <a:off x="0" y="0"/>
                              <a:ext cx="5720080" cy="3221355"/>
                            </a:xfrm>
                            <a:prstGeom prst="rect">
                              <a:avLst/>
                            </a:prstGeom>
                            <a:noFill/>
                            <a:ln>
                              <a:noFill/>
                              <a:miter lim="800000"/>
                              <a:headEnd/>
                              <a:tailEnd/>
                            </a:ln>
                          </pic:spPr>
                        </pic:pic>
                      </a:graphicData>
                    </a:graphic>
                  </wp:inline>
                </w:drawing>
              </w:r>
            </w:p>
    
  4. picCountU和picCount是我用来确保分配给它们的号码在文件中不存在的int变量。

    1. 然后我压缩所有相关元素,并将.zip重命名为.docx
    2. 我现在正处于整个文件状态的过程中,这个文件处于如此糟糕的状态,以至于它甚至无法打开。但没有太多。

      我检查了正文标记之前的序言,它看起来与我创建的包含图像的测试文档的序言相同。

      -

      我非常感谢给予的任何和所有帮助。

1 个答案:

答案 0 :(得分:0)

回答我自己的问题哈哈,我生命的故事。

对.docx结构的不熟悉是我的垮台。

  1. 我需要一个唯一的rId号码(此处为##)
  2. <a:blip r:embed="rId##" cstate="print"/>
    

    - &GT;这意味着我需要通过读取文件word / _rels / document.xls.rels

    来生成一个单独的数字
    1. 在此文档.xls.rels文件之前,我需要添加另一行,例如:
    2. <Relationship Id="rId##" 
      Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
      Target="media/image5.jpeg"/>
      

      其中image5.jpeg是我放入word / media文件夹的图像。它是如此,非常简单,而且有效。现在我只需要将该过程集成到几个.dxl文件中。