Back to Devexpress

ShapeCollection.InsertOleObject(DocumentPosition, String, String, Image) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-shapecollection-dot-insertoleobject-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentposition-system-dot-string-system-dot-string-system-dot-drawing-dot-image-x29.md

latest4.2 KB
Original Source

ShapeCollection.InsertOleObject(DocumentPosition, String, String, Image) Method

SECURITY-RELATED CONSIDERATIONS

Using file paths sourced from untrusted input may expose unauthorized files or allow unintended file access. Always validate and normalize all external paths to prevent path manipulation.

Inserts an OLE object that contains a link to 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
[Browsable(false)]
Shape InsertOleObject(
    DocumentPosition pos,
    string fileName,
    string progId,
    Image presentation
)
vb
<Browsable(False)>
Function InsertOleObject(
    pos As DocumentPosition,
    fileName As String,
    progId As String,
    presentation As Image
) As Shape

Parameters

NameTypeDescription
posDocumentPosition

The position of the object’s anchor.

| | fileName | String |

A path to the file associated with the OLE object.

| | progId | String |

The file type. You can use constant fields of the OleObjectType class to set this value.

| | presentation | Image |

The image that displays OLE object content.

|

Returns

TypeDescription
Shape

The OLE object added to the document.

|

Remarks

The following example adds a linked OLE object to the document:

csharp
Document document = wordProcessor.Document;
// Insert an OLE object. Link it to an Excel worksheet.
Shape oleObject = document.Shapes.InsertOleObject(document.CreatePosition(1780), @"D:\ExcelWorkbook.xlsx",
    OleObjectType.ExcelWorksheet, System.Drawing.Image.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
' Insert an OLE object. Link it to an Excel worksheet.
Dim oleObject As Shape = document.Shapes.InsertOleObject(document.CreatePosition(1780), "D:\ExcelWorkbook.xlsx", _ 
    OleObjectType.ExcelWorksheet, System.Drawing.Image.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

Open the document in Microsoft® Word® and double-click the image to open the file associated with the OLE object.

See Also

ShapeCollection Interface

ShapeCollection Members

DevExpress.XtraRichEdit.API.Native Namespace