Skip to content

Commit f78da48

Browse files
authored
Merge pull request #1833 from syncfusion-content/990103-OLEObject
UG documentation 990103: How to link an OLE Object to an Excel document and get the OLE part as stream from Worksheet
2 parents db1a603 + 7ced804 commit f78da48

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: Extract embedded OLE files from Excel as streams | Syncfusion
3+
description: This page shows how to extract embedded OLE objects from Excel as streams using the Syncfusion .NET Excel (XlsIO) library.
4+
platform: document-processing
5+
control: XlsIO
6+
documentation: UG
7+
---
8+
9+
# How to extract embedded OLE files from an Excel workbook as streams?
10+
11+
You can extract OLE objects in an Excel workbook as streams using XlsIO. The following example demonstrates how to retrieve embedded files from a worksheet.
12+
{% tabs %}
13+
{% highlight c# tabtitle="C# [Cross-platform]" %}
14+
using (ExcelEngine excelEngine = new ExcelEngine())
15+
{
16+
//Create worksheet
17+
IApplication application = excelEngine.Excel;
18+
application.DefaultVersion = ExcelVersion.Xlsx;
19+
IWorkbook workbook = application.Workbooks.Create(1);
20+
IWorksheet worksheet = workbook.Worksheets[0];
21+
22+
FileStream embedStream = new FileStream("../../../Sample.docx", FileMode.Open);
23+
FileStream imageStream = new FileStream("../../../wordIcon.jpg", FileMode.Open);
24+
25+
//Create image stream
26+
Image image = Image.FromStream(imageStream);
27+
28+
//Add ole object
29+
IOleObject oleObject = worksheet.OleObjects.Add(embedStream, image, OleObjectType.WordDocument);
30+
31+
// Get the OLE part stream.
32+
Image image1 = Image.FromStream(worksheet.OleObjects[0].GetEmbeddedOleStream());
33+
MemoryStream memory = new MemoryStream(image1.ImageData);
34+
35+
//Saving the workbook as stream
36+
FileStream stream = new FileStream("ExtractedFile.xlsx", FileMode.Create, FileAccess.Write);
37+
memory.CopyTo(stream);
38+
workbook.SaveAs(stream);
39+
stream.Dispose();
40+
}
41+
{% endhighlight %}
42+
43+
{% endtabs %}

0 commit comments

Comments
 (0)