2015-10-05 162 views
0

我有一個Base64編碼的圖像看起來像以下:如何從Base64編碼的圖像插入圖片在Word

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/Rqm5B6hmGG0wMtqv74G0MBA7AX00x3l3VWFYCZTB1HXEbNgNLNG5KYoZzkC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圖片在記憶中?

最好不使用系統剪貼板或從文件插入。

+0

哪個版本的Word(S)你瞄準? –

+0

MS Word 2010和2013 – orad

回答

2

從base64插入圖形的唯一可能性是使用Word Open XML。

爲了通過API執行此操作,需要以OPC平面文件格式生成有效的Word Open XML。這可以使用Range.InsertXML方法插入Word應用程序中打開的文檔中。

確定有效的Word Open XML是什麼的最簡單方法是使用Range.WordOpenXML屬性將其寫出到字符串中。例如,插入圖像作爲InlineShape然後Document.InlineShapes[index].Range.WordOpenXML;

或者,在VBA編輯器使用立即窗口和文檔中其寫入到當前選擇:

Selection.Text = ActiveDocument.InlineShapes(1).Range.WordOpenXML 

然後按Enter鍵。

您應該在XML中將圖像看作base64。

這將生成完整的完整的Word Open XML,您可以「按原樣」使用它,替換base64(並可能調整大小屬性)。但是您不需要爲InsertXML提供全部的功能。如果你想修剪下來,或更多地瞭解發生了什麼事情,本文介紹的最低要求是什麼,並提供更多的背景信息:

https://msdn.microsoft.com/en-us/library/office/dn423225.aspx