Method AppendOleObject
AppendOleObject(Paragraph, byte[], string, byte[], string, Emu, Emu, bool)
Appends an embedded OLE object to a paragraph: the payload bytes, the preview picture Word actually draws, and the markup that ties them together.
public static ShapeRef AppendOleObject(this Paragraph paragraph, byte[] payloadBytes, string progId, byte[] previewImageBytes, string previewContentType, Emu width, Emu height, bool shownAsIcon = false)
Parameters
paragraphParagraphThe paragraph. It must belong to a document, because the parts and relationships are document-level state.
payloadBytesbyte[]The embedded object's bytes, normally a compound file. The array is not copied; do not mutate it afterwards.
progIdstringThe programmatic identifier of the owning application, for example "Excel.Sheet.12".
previewImageBytesbyte[]The encoded preview picture. The array is not copied.
previewContentTypestringThe preview image content type, for example "image/png".
widthEmuThe display width.
heightEmuThe display height.
shownAsIconboolWhether the object displays as an icon rather than as its content.
Returns
Remarks
The preview is required rather than optional. Word renders the preview and does not
look at the payload until the object is activated, so an object without one is an
invisible object — and Word repairs documents whose v:shape has no
v:imagedata. Supplying the picture is the caller's job because only the caller
knows what the payload looks like; DocWright will not launch the owning application to
find out.
Both parts are added as preserved parts so the writer copies them verbatim, which is the same route the reader's own OLE payloads travel. DocWright never interprets the payload.
Exceptions
- ArgumentNullException
A required argument is null.
- ArgumentException
A byte array is empty,
progIdis empty, orpreviewContentTypeis not an image type.- ArgumentOutOfRangeException
widthorheightis not positive.- InvalidOperationException
The paragraph is not attached to a document.