簡體   English   中英

Word 2007,Open XML - 嵌入圖像

[英]Word 2007, Open XML - embedding an image

你知道什么基本信息必須在* .docx文檔中的document.xml中包含一個段落( <w:p/> ),它指定一個圖像嗎? 我知道必須有:

<a:blip r:embed="rId4" /> 

指定關系id,但還有什么? 很難在Google中找到它並嘗試從現成文檔中刪除標簽或閱讀規范需要花費大量時間。

將非常感謝所有必需標簽的示例。

關於提供的輸入XML,Word相當挑剔。 要嵌入圖像,您必須提供相當多的信息。 這是一個簡單的例子:

document.xml中

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" 
            xmlns:v="urn:schemas-microsoft-com:vml" 
            xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" 
            xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:body>
    <w:p>
      <w:r>
        <w:drawing>
          <wp:inline distT="0" distB="0" distL="0" distR="0">
            <wp:extent cx="5943600" cy="3717290"/>
            <wp:docPr id="1" name="Picture 0" descr="vlcsnap-325726.png"/>
            <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="0" name="myImage.png"/>
                    <pic:cNvPicPr/>
                  </pic:nvPicPr>
                  <pic:blipFill>
                    <a:blip r:embed="rId4"/>
                    <a:stretch>
                      <a:fillRect/>
                    </a:stretch>
                  </pic:blipFill>
                  <pic:spPr>
                    <a:xfrm>
                      <a:off x="0" y="0"/>
                      <a:ext cx="5943600" cy="3717290"/>
                    </a:xfrm>
                    <a:prstGeom prst="rect">
                      <a:avLst/>
                    </a:prstGeom>
                  </pic:spPr>
                </pic:pic>
              </a:graphicData>
            </a:graphic>
          </wp:inline>
        </w:drawing>
      </w:r>
    </w:p>
  </w:body>
</w:document>

document.xml.rels

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
  <!-- other relationships go here -->
  <Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="media/image1.png"/>
</Relationships>

當然,必須將圖像添加到正確位置的包裝中(media / image1.png)

由於所有這些都相當復雜,我建議您使用Microsoft提供的OpenXML SDK 2.0或其他庫,例如OpenXML4J 這些庫,尤其是Microsoft的庫,可以使您的工作更輕松。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM