OLE object (XLS) can not open after extract

A few days ago, I acquired Aspose Cells for Java. (version 24.1)

I am testing ole object extract in an excel file (xlsx).
There are 9 ole objects in various formats.
As a result of extraction, everything was extracted well.
However, only the XLS type does not open.
XLSX type opens well.
If you look at the size of the extracted XLS file, it looks normal.
image.png (11.9 KB)

And, there is no XLS value in FileFormatType ENUM.

FileFormatType.DOC → 31
FileFormatType.DOCX → 27
FileFormatType.PPT → 32
FileFormatType.PPTX → 26
FileFormatType.XLS → NULL
FileFormatType.XLSX → 6

I don’t know if this has anything to do with why the file doesn’t open, but
I think the problem is that this value is NULL.

Please respond on this issue.

@immal
By creating sample files and testing with the latest version v24.1, we can obtain the correct results. You cannot obtain the OLE object (XLS). Because it is linked to a file, OleObject.ObjectData is null. At this point, you can choose to get path from OleObject.ObjectSourceFullName, obtain the data, and then save it. Please check the attachment.result.zip (23.5 KB)

The sample code as follows:

// Open the template file.
Workbook workbook = new Workbook(filePath + "sample.xlsx");

// Get the OleObject Collection in the first worksheet.
Aspose.Cells.Drawing.OleObjectCollection oles = workbook.Worksheets[0].OleObjects;

// Loop through all the oleobjects and extract each object in the worksheet.
for (int i = 0; i < oles.Count; i++)
{
        Aspose.Cells.Drawing.OleObject ole = oles[i];
    // Specify the output filename.
    string fileName = filePath + "outOle" + i + ".";
    // Specify each file format based on the oleobject format type.
    switch (ole.FileFormatType)
    {
        case FileFormatType.Excel97To2003:
            fileName += "xls";
            break;
        case FileFormatType.Pptx:
            fileName += "pptx";
            break;
        case FileFormatType.Pdf:
            fileName += "pdf";
            break;
        case FileFormatType.Docx:
            fileName += "docx";
            break;
        default:
            //........
            break;
    }
    // Save the oleobject as a new excel file if the object type is xls.
    if (ole.FileFormatType == FileFormatType.Excel97To2003)
    {
        MemoryStream ms = new MemoryStream();
        if (ole.ObjectData != null)
        {
            ms.Write(ole.ObjectData, 0, ole.ObjectData.Length);
            Workbook oleBook = new Workbook(ms);
            oleBook.Settings.IsHidden = false;
            oleBook.Save(filePath + "outOle" + i + ".out.xls");
        }
        else if (ole.IsLink)
        {
            Workbook olebook = new Workbook(ole.ObjectSourceFullName);
            olebook.Save(filePath + "line_file" + i +"_out.xls");
        }
    }
    // Create the files based on the oleobject format types.
    else
    {
        if (ole.ObjectData != null)
        {
            FileStream fs = File.Create(fileName);
            fs.Write(ole.ObjectData, 0, ole.ObjectData.Length);
            fs.Close();
        }
    }
}

Hope helps a bit.

@immal,

Moreover, since you are using Java, so here is the parallel sample (Java) code for your reference.
e.g.
Sample code:

        String filePath = "f:\\files\\";
        // Open the template file.
        Workbook workbook = new Workbook(filePath + "sample.xlsx");

        // Get the OleObject Collection in the first worksheet.
        OleObjectCollection oles = workbook.getWorksheets().get(0).getOleObjects();

        // Loop through all the oleobjects and extract each object in the worksheet.
        for (int i = 0; i < oles.getCount(); i++) {
            OleObject ole = oles.get(i);
            // Specify the output filename.
            String fileName = filePath + "outOle" + i + ".";
            // Specify each file format based on the oleobject format type.
            switch (ole.getFileFormatType()) {
                case FileFormatType.EXCEL_97_TO_2003:
                    fileName += "xls";
                    break;
                case FileFormatType.PPTX:
                    fileName += "pptx";
                    break;
                case FileFormatType.PDF:
                    fileName += "pdf";
                    break;
                case FileFormatType.DOCX:
                    fileName += "docx";
                    break;
                default:
                    //........
                    break;
            }
            // Save the oleobject as a new excel file if the object type is xls.
            if (ole.getFileFormatType() == FileFormatType.EXCEL_97_TO_2003) {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                if (ole.getObjectData() != null) {
                    baos.write(ole.getObjectData(), 0, ole.getObjectData().length);
                    Workbook oleBook = new Workbook(new ByteArrayInputStream(baos.toByteArray()));
                    oleBook.getSettings().setHidden(false);
                    oleBook.save(filePath + "outOle" + i + ".out.xls");
                } else if (ole.isLink()) {
                    Workbook olebook = new Workbook(ole.getObjectSourceFullName());
                    olebook.save(filePath + "line_file" + i + "_out.xls");
                }
            }
            // Create the files based on the oleobject format types.
            else {
                if (ole.getObjectData() != null) {
                    FileOutputStream fos = new FileOutputStream(fileName);
                    fos.write(ole.getObjectData(), 0, ole.getObjectData().length);
                    fos.close();
                }
            }
        }

@John.He, @amjad.sahi

Thank you both for the quick replies.
Also, these were all helpful replies.
Thanks to you, I solved the problem.

The important key was to handle ‘FileFormatType.EXCEL_97_TO_2003’ separately.

Thank you very much.

Have a happy day~

@immal
Thank you for your feedback. You are welcome. If you have any questions, please feel free to contact us.