如何从Base64编码的图片插入Word中的图片
How to insert picture in Word from Base64 encoded image
我有一个 Base64 编码的图像,如下所示:
var base64SignatureImage = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOgAAACJCAMAAAAR34S1AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAMAUExURQAAAA8PDx8fHy8vLz8/P09PT19fX29vb39/f4+Pj5+fn6+vr7+/v8/Pz9/f3+/v7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAK/M6GAAAAEAdFJOU////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////wBT9wclAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGHRFWHRTb2Z0d2FyZQBwYWludC5uZXQgNC4wLjb8jGPfAAALWklEQVR4Xu2da6Ojqg6GQVFREdb//7PdCSAXwUsLtp211/thH6fTaX0ghCTEHvL4n+gP9LfpD/S36Q/0t+kP9LfpDzSvhXcNQVHGF/vav6FnQFWPkJRpUUKYsH/xL+g6qGBAOUzK/vEhx4b09vof0FVQxSlpPaXRRP8d0ougM2La60BLM9irezWVL5JLoKoDo7XXsRb6DpfUk8Zeva4roEtL6Gyvtxo7e3GjJnAOxVN6AXShhG0Wp5cg0l7dJ0rGoXiJnIMC54HLEeVjfaYJlo1s7R9e1imoojvL02ig9uI+tRTsqXiRnoIyMtqrrJrbNxipB5qVOr0zUE6YvcqK379EzVfw0hVyAqoo2s2uFsrt1X1q9fK8G3Qke/sKaqb3by7KLB2eCVee0gloc2S4I2mPpruOJrM4eKnpHIPOBxMqWtLdz/nojL/lR5Z1Rcegw94KVTNEhaXWdEnUbG43r1GWXYNqBErC7w+JQGtAcjMoyayMpYOcm3Rvqi9wYmxquBk0CRYUFhna4W1lFGa94X60fVEnoKUuoFirTd0cAr4hHjiWsEMtbwZlny6VjNYXjcU3cgz6htzkWL0BVeWmdQy6fGqRKjFzrouqLdZWm8NU8ZKOQR9NebHmWcmZAx9lHDSYKjLuZ33hkJ+AYnb/Rqm5B6hmGG0wMtqv74G0MBA7AX00x3l3VWFYCZTB1HXEbNgNLNG5KYo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的 Word 文档中?
最好不要使用系统剪贴板,或者从文件中插入。
从 base64 插入图形的唯一可能是使用 Word Open XML。
为了通过 API 执行此操作,您需要以 OPC flat-file 格式生成有效的 Word Open XML。这可以插入到使用 Range.InsertXML 方法在 Word 应用程序中打开的文档中。
确定有效 Word Open XML 是什么的最简单方法是使用 Range.WordOpenXML 属性 将其写入字符串。例如,将图像作为 InlineShape 插入,然后 Document.InlineShapes[index].Range.WordOpenXML;
或者,使用 VBA 编辑器中的 Immediate Window 并将其写入文档中的当前选择:
Selection.Text = ActiveDocument.InlineShapes(1).Range.WordOpenXML
然后按回车键。
您应该在 XML 中看到图像为 base64。
这会生成完整的 Word Open XML,您可以使用它 "as is",替换 base64(并可能调整大小属性)。但是对于 InsertXML,您不需要所有这些。如果您想 trim 降低它,或了解更多有关发生的事情,本文将解释最低要求并提供更多背景信息:
https://msdn.microsoft.com/en-us/library/office/dn423225.aspx
我有一个 Base64 编码的图像,如下所示:
var base64SignatureImage = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOgAAACJCAMAAAAR34S1AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAMAUExURQAAAA8PDx8fHy8vLz8/P09PT19fX29vb39/f4+Pj5+fn6+vr7+/v8/Pz9/f3+/v7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAK/M6GAAAAEAdFJOU////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////wBT9wclAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGHRFWHRTb2Z0d2FyZQBwYWludC5uZXQgNC4wLjb8jGPfAAALWklEQVR4Xu2da6Ojqg6GQVFREdb//7PdCSAXwUsLtp211/thH6fTaX0ghCTEHvL4n+gP9LfpD/S36Q/0t+kP9LfpDzSvhXcNQVHGF/vav6FnQFWPkJRpUUKYsH/xL+g6qGBAOUzK/vEhx4b09vof0FVQxSlpPaXRRP8d0ougM2La60BLM9irezWVL5JLoKoDo7XXsRb6DpfUk8Zeva4roEtL6Gyvtxo7e3GjJnAOxVN6AXShhG0Wp5cg0l7dJ0rGoXiJn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PwzvVAp3ymfj3/BRkJdCd3w/AZtQvUSVQni+s3dNX9pLqgO5MqD+b+bzqgO5MaNh59WnVAc1P6M7zr59RFdAp3xVgf+jkO1QFNP9zj7LCj8XWUw1QselfsOq/Z28B1QANWgMDLZlWsg+qBqjr+IuU9nB+VBVAtw/7Gc3f5HJBFUBdO2Ao5Vr9vkQVQLM+15xZf5HKQbMn5WFX/3eoHDT3+MD11t+3qRw0asW0ck8Gfo9uAR2+zOOi7gCd4+fXvkM3gC5nz0J9ROWg24dwl2/bQY3KQfXDjF5LzXaviioHfQRPruL8njdvfkQVQLmfUsmuNG9+RBVAH61tT1Kclv0a452qASobMggxdfst1V+gGqDYykLIl///i1UB/Rf0B/rb9Af62/QH+rv0ePwHhuJkw/TfPG4AAAAASUVORK5CYII=";
使用 Word Automation API,如何将此作为图片插入到内存中的 Word 文档中?
最好不要使用系统剪贴板,或者从文件中插入。
从 base64 插入图形的唯一可能是使用 Word Open XML。
为了通过 API 执行此操作,您需要以 OPC flat-file 格式生成有效的 Word Open XML。这可以插入到使用 Range.InsertXML 方法在 Word 应用程序中打开的文档中。
确定有效 Word Open XML 是什么的最简单方法是使用 Range.WordOpenXML 属性 将其写入字符串。例如,将图像作为 InlineShape 插入,然后 Document.InlineShapes[index].Range.WordOpenXML;
或者,使用 VBA 编辑器中的 Immediate Window 并将其写入文档中的当前选择:
Selection.Text = ActiveDocument.InlineShapes(1).Range.WordOpenXML
然后按回车键。
您应该在 XML 中看到图像为 base64。
这会生成完整的 Word Open XML,您可以使用它 "as is",替换 base64(并可能调整大小属性)。但是对于 InsertXML,您不需要所有这些。如果您想 trim 降低它,或了解更多有关发生的事情,本文将解释最低要求并提供更多背景信息:
https://msdn.microsoft.com/en-us/library/office/dn423225.aspx