Extract OpenXML Embedded OleObject in Aspose Cells Java

Hi There,

We have an Excel sheet that has embedded ole objects using OpenXML API in dot net. When we try to extract these objects using Aspose Cells java, it returns 0 embedded objects. However if we extract the Excel file manually we can see the objects and also Aspose Cells dot net API is able to recover those objects.

image.png (6.6 KB)

Can you confirm if Aspose Cells Java is able to do it?
And please share the code snippet if it can.

Thanks.

@sushil8282,

Aspose.Cells for Java does support to add, manipulate or extract Ole objects in the spreadsheets, please try latest version of the API. Please zip and attach your template Excel file containing the embedded Ole object(s). We will check your issue soon.

Workbook workbook = new Workbook(file.getAbsolutePath());
OleObjectCollection oles = workbook.getWorksheets().get(0).getOleObjects();

	for (int i = 0; i < oles.getCount(); i++) {
		if (oles.get(i).getMsoDrawingType() == MsoDrawingType.OLE_OBJECT) {
			OleObject ole = (OleObject) oles.get(i);
			FileOutputStream fos = new FileOutputStream(destinationFileLocation);
			byte[] data = ole.getObjectData();
			fos.write(data);
			fos.close();
		}
	}

Excel Test.zip (10.0 KB)

Steps:

  • I have put the excel file in a zip because can’t upload .xlsx file here. So extract the file to get Excel Test.xlsx
  • Run the file with above code (Java), oles.getCount() comes out to be 0
  • But if you do the same thing with dot net it is 1
  • Also if you just extract the Excel file you will find a “package.bin” file under Embeddings folder
1 Like

@sushil8282,

I tested your scenario/case a bit. I opened your file into MS Excel 2016 and 2007 manually but could not spot the OLE Object in it. I got description text “Add-on not installed please install the Add-on” in A1 cell in the sheet. Also, I tried to spot the Ole Object by using Find @ Select|Selection Pane in MS Excel but still do not find the Ole Object in it. See the screenshot attached for your reference.
sc_shot1.png (49.5 KB)

Could you give us details on how could we see/find Ole Object in MS Excel manually?

As mentioned in the previous message:

  • But if you do the same thing with dot net it is 1
  • Also if you just extract the Excel file you will find a “package.bin” file under Embeddings folder

Can you please try to follow the above steps? The embedded object is encrypted, that is why you wont be able to open it but it should be found using Aspose Cells (Java)

Excel.zip (16.2 KB)

I have attached another file. This has embedded object but using Aspose Cells (Java) instead of OpenXML (dot net).

This file has the same structure but in this case oles.getCount() is 1

I guess “dot net” you mean OpenXML.
Aspose.Cells follows MS Excel standards and specifications. if any OLE Object is not shown/detected in MS Excel manually, Aspose.Cells might not detect it whether it is encrypted or not. So, it is not an issue with Aspose.Cells by any means.

When I opened your new file, I can find MS Excel shows/detects an Ole Object in it. That’s why Aspose.Cells for Java does give count to 1.

Thanks, but the question is that if we can manually find the Ole object embedded in the first Excel file (OpenXML created), why Aspose Cells (Java) is not able to find it?

Following snippet if from Aspose Cells (dot net), which is able to extract embedded object from the first Excel but not the similar code in Aspose Cells (Java)

 Workbook workbook = new Workbook(FileName);
            OleObjectCollection oles = workbook.Worksheets[0].OleObjects;
            string ZipfilePath = GetZipPath(EmbeddedFile);
            for (int i = 0; (i < oles.Count()); i++)
            {
                if ((oles[i]).MsoDrawingType == MsoDrawingType.OleObject)
                {
                    OleObject ole = ((OleObject)(oles[i]));
                    FileStream fos = new FileStream(ZipfilePath, System.IO.FileMode.Create);
                    byte[] data = ole.ObjectData;
                    fos.Write(data, 0, data.Length);
                    fos.Close();
                }

            }

@sushil8282
For the first excel, the embedded data in the template file has not been referenced by the worksheet, so it should not exist in the worksheet’s ole object collection. Just like that fact that when you open this file in ms excel, you cannot find any ole object either.

If that is not referenced by the worksheet then can you please explain how is it being found by the below code?

Workbook workbook = new Workbook(FileName);
OleObjectCollection oles = workbook.Worksheets[0].OleObjects;
string ZipfilePath = GetZipPath(EmbeddedFile);
for (int i = 0; (i < oles.Count()); i++)
{
if ((oles[i]).MsoDrawingType == MsoDrawingType.OleObject)
{
OleObject ole = ((OleObject)(oles[i]));
FileStream fos = new FileStream(ZipfilePath, System.IO.FileMode.Create);
byte[] data = ole.ObjectData;
fos.Write(data, 0, data.Length);
fos.Close();
}

        }

This snippet is from Aspose Cells (dot net)

Again for clarification; Aspose Cell (dot net) is able to extract it but not Aspose Cells (Java)

Please ignore. We might be using different code in dot net to extract it. Thanks for the help.

@sushil8282
Though there is a file named as “xl\worksheets\embeddings\package.bin” in “Excel test.xlsx”,there is no any reference to it in “Sheet1.xml”, so the file “xl\worksheets\embeddings\package.bin” should be ignored and there is no Embedded OleObject too.Aspose.Cells works same as MS Excel.

Thanks for looking into it.