Free Support Forum - aspose.com

Checking for Embedded OLE Objects

Hi,

I am using Cells to extract all embedded OLE Objects from Excel Spreadsheets, and I was wondering if there was a way to simply access an Excel file and check if there are any OLE objects in it without actually looping through all of the worksheets within it. Thanks!

Tom

Hi,

May the following sample code, help you for your need:

//Instantiating a Workbook object
Workbook workbook = new Workbook();
workbook.Open(@"D:\test\bkEmbeddedExtraction.xls");
//Loop through all the worksheets
for( int cnt = 0; cnt<workbook.Worksheets.Count; cnt++)
{
//Get the ole objects in the current worksheet.
OleObjects oles = workbook.Worksheets[cnt].OleObjects;
MessageBox.Show(oles.Count.ToString());
for(int i = 0; i < oles.Count ; i++)
{
OleObject ole = oles[i];
//MessageBox.Show(ole.SourceFullName);
string fileName = "d:\\test\\t3ole" + cnt + i + ".";
switch (ole.FileType)
{
case OleFileType.Doc:
fileName += "Doc";
break;
case OleFileType.Xls:
fileName += "Xls";
break;
case OleFileType.Ppt:
fileName += "Ppt";
break;
case OleFileType.Pdf:
fileName += "Pdf";
break;
case OleFileType.Unknown:
fileName += "jpg";
break;
default:
fileName += "data";
break;
}
FileStream file = File.Create(fileName);
byte[] data = ole.ObjectData;
file.Write(data, 0, data.Length);
}

}

Thank you.

Thanks, this is the code I already have. Your software is so fast, I don’t think I NEED to find a new way to do it!

Tom