Back to Devexpress

NestedShapeCollection.AddOleObject(String, String, Image, RectangleF) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-nestedshapecollection-dot-addoleobject-x28-system-dot-string-system-dot-string-system-dot-drawing-dot-image-system-dot-drawing-dot-rectanglef-x29.md

latest5.2 KB
Original Source

NestedShapeCollection.AddOleObject(String, String, Image, RectangleF) 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.

Adds a linked OLE object to a shape group or a drawing canvas. 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)]
NestedShape AddOleObject(
    string fileName,
    string progId,
    Image presentation,
    RectangleF bounds
)
vb
<Browsable(False)>
Function AddOleObject(
    fileName As String,
    progId As String,
    presentation As Image,
    bounds As RectangleF
) As NestedShape

Parameters

NameTypeDescription
fileNameString

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.

| | bounds | RectangleF |

An object that defines the object’s size and location (relative to the top left corner of the parent object). The Document.Unit property specifies measurement units.

|

Returns

TypeDescription
NestedShape

The OLE object in the group or drawing canvas.

|

Remarks

The example below shows how to group two OLE objects. Use the ShapeCollection.InsertGroup method to create a shape group. The Shape.GroupItems property returns a collection of group elements. Call the AddOleObject methods to add OLE objects to the group.

csharp
Document document = wordProcessor.Document;
// Set measurement unit to inches.
document.Unit = DevExpress.Office.DocumentUnit.Inch;
// Insert a shape group.
Shape group = document.Shapes.InsertGroup(document.Range.Start);
// Access the collection of group items. 
var groupItems = group.GroupItems;
// Add the first OLE object to the group.
// This object contains data from an Excel worksheet.
using (Stream excelStream = File.Open(@"D:\ExcelWorkbook.xlsx", FileMode.Open))
{
    groupItems.AddOleObject(excelStream, OleObjectType.ExcelWorksheet,
        System.Drawing.Image.FromFile(@"Images\Spreadsheet.png"), new PointF(0f, 0f));
}
// Add the second OLE object to the group.
// The object links to an Excel chart sheet.
groupItems.AddOleObject(@"D:\ExcelChart.xlsx", OleObjectType.ExcelChart,
    System.Drawing.Image.FromFile(@"Images\ExcelChart.png"), new RectangleF(0.5f, 1.2f, 5f, 3.5f));
vb
Dim document As Document = wordProcessor.Document
' Set measurement unit to inches.
document.Unit = DevExpress.Office.DocumentUnit.Inch
' Insert a shape group.
Dim group As Shape = document.Shapes.InsertGroup(document.Range.Start)
' Access the collection of group items. 
Dim groupItems As GroupShapeCollection = group.GroupItems
groupItems = group.GroupItems
' Add the first OLE object to the group.
' This object contains data from an Excel worksheet.
Using excelStream As Stream = File.Open("D:\ExcelWorkbook.xlsx", FileMode.Open)
    groupItems.AddOleObject(excelStream, OleObjectType.ExcelWorksheet, _
    System.Drawing.Image.FromFile("Images\Spreadsheet.png"), New PointF(0F, 0F))
End Using
' Add the second OLE object to the group.
' The object links to an Excel chart sheet.
groupItems.AddOleObject("D:\ExcelChart.xlsx", OleObjectType.ExcelChart, _
  System.Drawing.Image.FromFile("Images\ExcelChart.png"), New RectangleF(0.5F, 1.2F, 5F, 3.5F))

See Also

NestedShapeCollection Interface

NestedShapeCollection Members

DevExpress.XtraRichEdit.API.Native Namespace