We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Oleobject raw data is null in Word

Hi Team,

I’m trying to implement a solution which detects office files embedded into word files and determines the filesize of each of the detected files.

For that I’m trying to utilize the GetChildNodes interface to get a list of embedded Shape nodes then filter these by the presence of OleFormat property to identify OLEObjects.
Once it is done, I’m trying to utilize the GetRawData method to access the underlying byte[] of the object and determine the size using it’s Length property.
However GetRawData returns null.

Please find attached a test application that reproduces the issue.
WordEmbeddedOleObjectRawDataIsNull.zip (243.9 KB)

Please confirm if this is a bug or I’m misusing this interface.
Thank you

Platform: .NET Core 3.1 Windows
Apose.Words: v21.8.0

@zpopswat,

We tested the scenario and have managed to reproduce the same problem on our end. The Shape.OleFormat.GetRawData method is returning null for all three Word DOCX files you shared. For the sake of any correction in Aspose.Words API, we have logged this problem in our issue tracking system with ID WORDSNET-22666. We will further look into the details of this problem and will keep you updated here on the status of linked issue. We apologize for your inconvenience.

As a workaround, you may use the following C# code:

using Aspose.Words;
using Aspose.Words.Drawing;
using System;
using System.IO;

namespace CustomerNumberDetectionInWord
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] files = new string[] { "Excel in word.docx", "Word in word.docx", "Slideshow in word.docx" };

            for (int i = 0; i < files.Length; ++i)
            {
                System.Console.WriteLine($"============================= processing {files[i]} ===============================");

                Document wordsDocument = new Document(files[i]);
                NodeCollection shapes = wordsDocument.GetChildNodes(NodeType.Shape, true);
                foreach (Shape shape in shapes)
                {
                    if (null != shape.OleFormat)
                    {
                        using (MemoryStream stream = new MemoryStream())
                        {
                            shape.OleFormat.Save(stream);
                            Console.WriteLine(stream.Length);
                        }
                    }
                }

                System.Console.WriteLine($"============================= processing {files[i]} DONE ===========================\n");
            }
            Console.Read();
        }
    }
}
1 Like