Find if Excel has any embedded objects

Is there any built-in functionality to find out if my excel has an embedded object (exe etc)?


Thanks,
Suraj

Hi Suraj,

Thanks for your posting and using Aspose.Cells.

You can find if the worksheet has Ole objects or not using Worksheet.OleObjects property. Please check its Count, if the Count is >0 then it has Ole objects and if it is =0 then it does not have any Ole objects.

Please see the following sample code. I have attached the source Excel file used in this code and extracted Ole objects for your reference. The source Excel file has actually two ole objects. One is Exe and other is PDF.

I have also shown the console output of this code and tested this issue with the latest version: Aspose.Cells
for .NET v8.3.2.5
.

For your more help, please see the following documentation article.


C#

//Create workbook object from source Excel file

Workbook workbook = new Workbook(“source.xlsx”);


//Access first worksheet

Worksheet worksheet = workbook.Worksheets[0];


//Check if this worksheet has embedded objects

Console.WriteLine(worksheet.OleObjects.Count);


//Extract Exe

byte[] oleBytes = worksheet.OleObjects[0].ObjectData;

File.WriteAllBytes(“output.exe”, oleBytes);


//Extract PDF

oleBytes = worksheet.OleObjects[1].ObjectData;

File.WriteAllBytes(“output.pdf”, oleBytes);


Console Output:
2