Back to Devexpress

ShapeCollection.InsertOleObject(DocumentPosition, Stream, String, DocumentImageSource) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-shapecollection-dot-insertoleobject-x28-documentposition-stream-string-documentimagesource-x29.md

latest4.3 KB
Original Source

ShapeCollection.InsertOleObject(DocumentPosition, Stream, String, DocumentImageSource) Method

Inserts an OLE object that stores data from the specified file. The object is displayed in the document as an image.

Namespace : DevExpress.XtraRichEdit.API.Native

Assembly : DevExpress.RichEdit.v25.2.Core.dll

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
Shape InsertOleObject(
    DocumentPosition pos,
    Stream stream,
    string progId,
    DocumentImageSource presentation
)
vb
Function InsertOleObject(
    pos As DocumentPosition,
    stream As Stream,
    progId As String,
    presentation As DocumentImageSource
) As Shape

Parameters

NameTypeDescription
posDocumentPosition

The position of the object’s anchor.

| | stream | Stream |

A stream that contains data to embed in the document.

| | progId | String |

Embedded content type. You can use constant fields of the OleObjectType class to set this value.

| | presentation | DocumentImageSource |

The source for the image that displays OLE object content.

|

Returns

TypeDescription
Shape

The OLE object added to the document.

|

Remarks

The following example embeds an OLE object in the document:

csharp
Document document = wordProcessor.Document;
// Embed data from an Excel worksheet in the document.
using (Stream excelStream = File.Open(@"D:\ExcelWorkbook.xlsx", FileMode.Open))
{
    Shape oleObject = document.Shapes.InsertOleObject(document.CreatePosition(1780), excelStream,
        OleObjectType.ExcelWorksheet, DocumentImageSource.FromFile(@"Images\Spreadsheet.png"));
    // Specify the object position on the page.
    oleObject.RelativeHorizontalPosition = ShapeRelativeHorizontalPosition.Column;
    oleObject.RelativeVerticalPosition = ShapeRelativeVerticalPosition.Paragraph;
    oleObject.Offset = new PointF(0, 0);
    // Specify how text wraps around the object. 
    oleObject.TextWrapping = TextWrappingType.TopAndBottom;
}
vb
Dim document As Document = wordProcessor.Document
' Embed data from an Excel worksheet in the document.
Using excelStream As Stream = File.Open("D:\ExcelWorkbook.xlsx", FileMode.Open)
    Dim oleObject As Shape = document.Shapes.InsertOleObject(document.CreatePosition(1780), excelStream, _
    OleObjectType.ExcelWorksheet, DocumentImageSource.FromFile("Images\Spreadsheet.png"))
    ' Specify the object position on the page.
    oleObject.RelativeHorizontalPosition = ShapeRelativeHorizontalPosition.Column
    oleObject.RelativeVerticalPosition = ShapeRelativeVerticalPosition.Paragraph
    oleObject.Offset = New PointF(0, 0)
    ' Specify how text wraps around the object. 
    oleObject.TextWrapping = TextWrappingType.TopAndBottom
End Using

Open the document in Microsoft® Word® and double-click the OLE object to modify the embedded data.

See Also

ShapeCollection Interface

ShapeCollection Members

DevExpress.XtraRichEdit.API.Native Namespace