Table of Contents

Method AppendOleObject

Namespace
DocWright.Dom.Editing
Assembly
DocWright.Dom.dll

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

paragraph Paragraph

The paragraph. It must belong to a document, because the parts and relationships are document-level state.

payloadBytes byte[]

The embedded object's bytes, normally a compound file. The array is not copied; do not mutate it afterwards.

progId string

The programmatic identifier of the owning application, for example "Excel.Sheet.12".

previewImageBytes byte[]

The encoded preview picture. The array is not copied.

previewContentType string

The preview image content type, for example "image/png".

width Emu

The display width.

height Emu

The display height.

shownAsIcon bool

Whether the object displays as an icon rather than as its content.

Returns

ShapeRef

The appended shape, carrying the OleObject description.

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, progId is empty, or previewContentType is not an image type.

ArgumentOutOfRangeException

width or height is not positive.

InvalidOperationException

The paragraph is not attached to a document.