尝试将图像插入到 wordML 时出错

发布于 2024-08-26 23:18:21 字数 3606 浏览 13 评论 0原文

需要帮助。

遇到此错误,

{"The xml has invalid content and cannot be constructed as an element.\r\nParameter name: outerXml"}

我在将构造的 xml 传递到 DocumentFormat.OpenXml.Office.Drawing.Drawing() 构造函数时

DocumentFormat.OpenXml.Office.Drawing.Drawing d = new DocumentFormat.OpenXml.Office.Drawing.Drawing(img);

如下所示这是传入的 xml

<w:drawing xmlns:w="http://schemas.openxmlformats.org/drawingml/2006/main">
                <wp:anchor distT="0" distB="0" distL="114300" distR="114300" simplePos="0" relativeHeight="251658240" behindDoc="0" locked="0" layoutInCell="1" allowOverlap="1" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing">
                  <wp:simplePos x="0" y="0"/>
                  <wp:positionH relativeFrom="column">
                    <wp:align>right</wp:align>
                  </wp:positionH>
                  <wp:positionV relativeFrom="paragraph">
                    <wp:align>top</wp:align>
                  </wp:positionV>
                  <wp:extent cx="400" cy="400"/>
                  <wp:effectExtent l="19050" t="0" r="0" b="0"/>
                  <wp:wrapSquare wrapText="bothSides"/>
                  <wp:docPr id="1" name="image"/>
                  <wp:cNvGraphicFramePr>
                    <a:graphicFrameLocks noChangeAspect="1" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
                  </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="0" name="image"/>
                          <pic:cNvPicPr>
                            <a:picLocks noChangeAspect="1" noChangeArrowheads="1"/>
                          </pic:cNvPicPr>
                        </pic:nvPicPr>
                        <pic:blipFill>
                          <a:blip r:embed="rIdImg4" cstate="print" xmlns:r="http://schemas.openxmlformats.org/drawingml/2006/relationships"/>
                          <a:stretch>
                            <a:fillRect/>
                          </a:stretch>
                        </pic:blipFill>
                        <pic:spPr bwMode="auto">
                          <a:xfrm>
                            <a:off x="0" y="0"/>
                            <a:ext cx="400" cy="400"/>
                          </a:xfrm>
                          <a:prstGeom prst="rect">
                            <a:avLst/>
                          </a:prstGeom>
                          <a:noFill/>
                          <a:ln w="9525">
                            <a:noFill/>
                            <a:miter lim="800000"/>
                            <a:headEnd/>
                            <a:tailEnd/>
                          </a:ln>
                        </pic:spPr>
                      </pic:pic>
                    </a:graphicData>
                  </a:graphic>
                </wp:anchor>
              </w:drawing>

谢谢, 基鲁

Help needed.

I am getting this error

{"The xml has invalid content and cannot be constructed as an element.\r\nParameter name: outerXml"}

while passing constructed xml in to DocumentFormat.OpenXml.Office.Drawing.Drawing() constructor like this

DocumentFormat.OpenXml.Office.Drawing.Drawing d = new DocumentFormat.OpenXml.Office.Drawing.Drawing(img);

Here is the xml which is passed in

<w:drawing xmlns:w="http://schemas.openxmlformats.org/drawingml/2006/main">
                <wp:anchor distT="0" distB="0" distL="114300" distR="114300" simplePos="0" relativeHeight="251658240" behindDoc="0" locked="0" layoutInCell="1" allowOverlap="1" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing">
                  <wp:simplePos x="0" y="0"/>
                  <wp:positionH relativeFrom="column">
                    <wp:align>right</wp:align>
                  </wp:positionH>
                  <wp:positionV relativeFrom="paragraph">
                    <wp:align>top</wp:align>
                  </wp:positionV>
                  <wp:extent cx="400" cy="400"/>
                  <wp:effectExtent l="19050" t="0" r="0" b="0"/>
                  <wp:wrapSquare wrapText="bothSides"/>
                  <wp:docPr id="1" name="image"/>
                  <wp:cNvGraphicFramePr>
                    <a:graphicFrameLocks noChangeAspect="1" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
                  </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="0" name="image"/>
                          <pic:cNvPicPr>
                            <a:picLocks noChangeAspect="1" noChangeArrowheads="1"/>
                          </pic:cNvPicPr>
                        </pic:nvPicPr>
                        <pic:blipFill>
                          <a:blip r:embed="rIdImg4" cstate="print" xmlns:r="http://schemas.openxmlformats.org/drawingml/2006/relationships"/>
                          <a:stretch>
                            <a:fillRect/>
                          </a:stretch>
                        </pic:blipFill>
                        <pic:spPr bwMode="auto">
                          <a:xfrm>
                            <a:off x="0" y="0"/>
                            <a:ext cx="400" cy="400"/>
                          </a:xfrm>
                          <a:prstGeom prst="rect">
                            <a:avLst/>
                          </a:prstGeom>
                          <a:noFill/>
                          <a:ln w="9525">
                            <a:noFill/>
                            <a:miter lim="800000"/>
                            <a:headEnd/>
                            <a:tailEnd/>
                          </a:ln>
                        </pic:spPr>
                      </pic:pic>
                    </a:graphicData>
                  </a:graphic>
                </wp:anchor>
              </w:drawing>

Thanks,
Kiru

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清旖 2024-09-02 23:18:21

您从 XML 创建的元素位于 Drawing 命名空间内。 (通常使用“a:”前缀。)从 OuterXml 字符串创建这些元素时,根节点必须与所创建的对象的类型相对应。 (在本例中为 DocumentFormat.OpenXml.Office.Drawing.Drawing)。这里的问题是 XML 根节点用于不同的元素。

尝试创建一个 DocumentFormat.OpenXml.WordProcessing.Drawing() 对象:
http://msdn.microsoft.com/en-us /library/documentformat.openxml.wordprocessing.drawing.aspx

找到注入 DrawingML 的正确级别可能很困难。使用 OpenXmlSDK 工具查看哪些节点下有效。祝你好运!

The element you are creating from the XML is within the Drawing namespace. (Often seen using the "a:" prefix.) When creating these elements from OuterXml strings the root node must correspond with the type of the object being created. (In this case a DocumentFormat.OpenXml.Office.Drawing.Drawing). The problem here is that the XML root node is for a different element.

Try creating a DocumentFormat.OpenXml.WordProcessing.Drawing() object:
http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.drawing.aspx

It can be difficult finding the right level at which to inject the drawingML. Get out the OpenXmlSDK tool to see what is valid under which nodes. Best of luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文