Free Support Forum - aspose.com

Extracting MS Word file from OLE Object using Aspose.Slides for .NET

@rausch,

It is good to know that you have been able to extract the Word file from OLE. You can work on that file and save that a Word file. Then you load the OLE file using stream and don’t forget to set the position of loaded stream to 0. The convert the stream to byte array and set that as OLE data. I hope this will work. If you find any issue then please share a working scenario (sample project) that we may use to reproduce issue on our end and help you.

I suggest you to please try using following sample code to add image to Ole frame. The oof is OleObjectFrame object.

Bitmap imgChart = "Any Bitmap";
oof.SubstitutePictureFormat.Picture.Image = pres.Images.AddImage(imgChart);

Hello,

I did add the picture and it works.
Somehow, I do not know why at the moment storing the Word OLE object in PP does not work anymore, but worked before. Made a simple test where it works. So do not understand why the object is corrupt now again. Do you have sample code how to add it ?

I did

          compoundFile = new CompoundFile();
          compoundFile.RootStorage.AddStream("Package").SetData(wordStream);
          ole.ObjectData = compoundFile.RootStorage.GetStream("Package").GetData();

but do not work anymore 2hours later for reason I do not understand.

Here is sample code to reproduce the problem:

static void Main(string[] args)
    {
      // document
      var source = @"C:\repositories\latest\src\TQsoft\AsposeSlideTest\AsposeSlideTest\powerpoint.pptx";
      var target = @"C:\repositories\latest\src\TQsoft\AsposeSlideTest\AsposeSlideTest\word.docx";
      var targetP = @"C:\repositories\latest\src\TQsoft\AsposeSlideTest\AsposeSlideTest\powerpointP.pptx";

      var _presentation = new Presentation(source);

      var presentationSlides = _presentation.Slides;
      foreach (var presentationSlide in presentationSlides)
      {
        var shapes = presentationSlide.Shapes;
        foreach (var shape in shapes)
        {
          if (!(shape is OleObjectFrame)) continue;
          var ole = shape as OleObjectFrame;
          if (!ole.ObjectProgId.Contains("Word.Document")) continue;
          ole.UpdateAutomatic = true;

          using (var ms = new MemoryStream(ole.ObjectData))
          {
            ms.Position = 0;

            var compoundFile = new CompoundFile(ms);
            var stream = compoundFile.RootStorage.GetStream("Package");
            var packageData = stream.GetData();

            using (var packageDataStream = new MemoryStream(packageData))
            {
              var word = new Document(packageDataStream);
              word.Save(target);
              var wordStream = new MemoryStream();
              word.Save(wordStream, Aspose.Words.SaveFormat.Docx);
              wordStream.Position = 0;

              // try 1
              //compoundFile = new CompoundFile();
              //compoundFile.RootStorage.AddStream("Package").SetData(wordStream.ToArray());
              //ole.ObjectData = compoundFile.RootStorage.GetStream("Package").GetData();

              // try 2
              ole.ObjectData = wordStream.ToArray();
            }
            
          }
        }
      }

      _presentation.Save(targetP, SaveFormat.Pptx);
    }

@rausch,

I have observed the sample code and there seems nothing wrong in as far as updating OLE data is concerned. I request you to please provide a source word file and modified word file along with a sample solution that I may use on your end by compiling same dependencies as used on your end. Please provide requested information so that I may be able to investigate the issue further on my end.

Here is a sample project I use including a PowerPoint with embedded Word.

Hmm tried to upload, 3 times. is it there?

@rausch,

I am unable to observe any download link or attachment in your last reply. Can you please check again.

AsposeSlideTest.zip (295.7 KB)

Ok worked, now, since a few days I face many timeouts on this forum loading or saving data.

@rausch,

Thank you for sharing the information with us. I have worked with sample project shared and have created an issue with ID SLIDESNET-39874 in our issue tracking system to further investigate and resolve the issue. I also request you to please provide the generated presentation file on your end as well for reference. The generated file on my end has been attached as well for your reference.

powerpointP.zip (126.5 KB)

Any news? As still it seems not to work yet. Is important for us!

@rausch,

I have verified from our issue tracking system and regret to share that the concerned issues was going to be resolved (owing to complexities in API) no sooner than Q2 of 2018. But this issue is more important to you so we have raised issue priority. We will share good news with you soon.

Hello,
any news so far, in change history I did not ready anything about it so far.

@rausch,

I have verified from our issue tracking system and regret to share that at present the issues are not resolved. However, I have requested for updates and will get back to you with you feedback as soon as possible.

Ok, please do so, thanks.
This issue is years old, I am Total.Net subscription customer (biggest version) since years and waiting… this might be less prio to most of your customers, but I am one of those customers, too.

@rausch,

I have observed your comments and raised issue priority from medium to high. I also like to inform that in Aspose.Slides forum the issues are selected for investigation on first come first serve basis. Also the first priority for scheduling and resolution is given to paid Enterprise and priority support customers. Then Aspose.Slides normal or free support customers issues are scheduled and resolved on first come and first come serve basis. I will share the further information with you as soon as the issue will be resolved. I request for your patience.

Ok, first of all, I am enterprise users since over 5 years now. Second I do pay aspose.total subscription every year. Another hint: This issue is 3 years old or older, so first comes, first is doesnt really affect here…

@rausch,

If you have paid support subscription then you can log a ticket in Paid Support help desk separately.

@rausch,

We have investigated your following issue:

We like you to understand that compound file is just a storage for OLE object so before placing OLE object into compound storage it must be created. For more information you can please see this link. In your code you can use existing compound storage:


var _presentation = new Presentation(source);

var presentationSlides = _presentation.Slides;
foreach (var presentationSlide in presentationSlides)
{
var shapes = presentationSlide.Shapes;
foreach (var shape in shapes)
{
if (!(shape is OleObjectFrame)) continue;
var ole = shape as OleObjectFrame;
if (!ole.ObjectProgId.Contains(“Word.Document”)) continue;

    using (var ms = new MemoryStream(ole.ObjectData))
    {
        var compoundFile = new CompoundFile(ms);
        var stream = compoundFile.RootStorage.GetStream("Package");
        var packageData = stream.GetData();

        using (var packageDataStream = new MemoryStream(packageData))
        {
            var word = new Document(packageDataStream);
            word.Save(target);
            var wordStream = new MemoryStream();

            word = new Document(target);
            word.Save(wordStream, Aspose.Words.SaveFormat.Docx);
            wordStream.Position = 0;

            // Do not create new compound storage. Just change package stream in existing one.
            compoundFile.RootStorage.Delete("Package");
            compoundFile.RootStorage.AddStream("Package").SetData(wordStream.ToArray());

            // save compound file back to ObjectData. Not stream but compound storage.
            MemoryStream compMs = new MemoryStream();
            compoundFile.Save(compMs);
            ole.ObjectData = compMs.ToArray();
        }
    }
}

}

Please not that currently Ole control window opens in wrong size. This issue is likely to get fixed in Aspose.Slides for .NET19.11. Please also notice that new Ole object won’t show new image representation of it because of Aspose.Slides can’t create images from non-presentation objects. I hope the shared information will be helpful.

The issues you have found earlier (filed as SLIDESNET-39130,SLIDESNET-39874) have been fixed in this update.

Hello,
I did try new component. Ole in PowerPoint is not corrupted anymore. Thats a good step.
Nevertheless the provided solution still does not work for me.

It looks like, that this does to update correct:

            // Do not create new compound storage. Just change package stream in existing one.
            compoundFile.RootStorage.Delete("Package");
            compoundFile.RootStorage.AddStream("Package").SetData(wordStream.ToArray());

If I do

          compoundFile.Save("c:\\test.docx");

and check it after in Word, the compoundFile content is still the same as before modification.

NOTE: If I save the wordStream I have directly to file system and check I have a modified word document.

In addition do I still need to use OpenMcdf or can’t I just add the wordStream.ToArray() to the ole.ObjectData ?? This word perfect in Aspose.Cells…

Please try yourself get embedded word, modify anything inside this word after loading and save the modified word back to PowerPoint OLE object. I think you did not try this before, do you?

@rausch,

It’s good to know things are fine on your end. I like to share that you need to use the sample that I have shared previously with you for extraction.

I think I wrote misunderstanding. Of course I tried your code sample.
The Word gets extracted correctly, the PowerPoint is not corrupted anymore after saving like before latest release, but the modified Word content is not embedded.
Thats why I asked if you changed any content to compare PowerPoint before and after!?