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

Free Support Forum - aspose.com

Modify Embed Word Text In Slide

By Aspose.slides for java , how to read and modify the text and shapes of embed word in slide?

@youzi,

I have observed your requirements and like to share that you can access the shapes with text using Aspose.Slides and can update the text in presentation. Please visit this documentation link to serve the purpose on your end.

Many Thanks,

Mudassir Fayyaz

thanks your reply, but I want to read and modify the text of the embed word file , not the textbox or shape in pptx. like the photo shown.image.png (35.3 KB)

@youzi,

I have observed your requirements and like to share that in order to access the Word Ole object you can access the Ole Object using Aspose.Slides and then extract the Ole data using Aspose.Words. We don’t have a public API which will allow to extract this stream and use as ready-to-use Word document, but it can be easily achieved using third-party open source library, such as OpenMcdf.

First, you need to reference this library. It’s available as NuGet package, and you can add it to your project using Package Manager Console:

Install-Package OpenMcdf

Then, the following sample code can be use to work with embedded document using Aspose.Slides and Aspose.Words:

using (Presentation pres = new Presentation("Presentation.pptx"))
{
ISlideCollection slides = pres.Slides;

foreach (ISlide presentationMasterSlide in slides)
{
    IShapeCollection shapes = presentationMasterSlide.Shapes;
    foreach (IShape shape in shapes)
    {
        if (shape is OleObjectFrame)
        {
            OleObjectFrame oleObjectFrame = (OleObjectFrame)shape;
            if (!oleObjectFrame.ObjectProgId.Contains("Word.Document"))
            {
                continue;
            }

            oleObjectFrame.UpdateAutomatic = true;

            using (MemoryStream memoryStream = new MemoryStream(oleObjectFrame.ObjectData))
            {
                memoryStream.Position = 0;
                OpenMcdf.CompoundFile compoundFile = new CompoundFile(memoryStream);
                OpenMcdf.CFStream stream = compoundFile.RootStorage.GetStream("Package");
                byte[] packageData = stream.GetData();

                using (MemoryStream packageDataStream = new MemoryStream(packageData))
                {
                    Document word = new Document(packageDataStream);
                    word.Save("Document.docx", Aspose.Words.SaveFormat.Docx);                                    
                }
            }
        }
    }
}

}

Many Thanks,

Mudassir Fayyaz

thanks your reply,but I use the aspose.slides for java, so I cannot use the OpenMcdf.What is the available third-party open source library.Besides,for the following code, please change them to java code.

       using (MemoryStream memoryStream = new MemoryStream(oleObjectFrame.ObjectData))
         {
            memoryStream.Position = 0;
            OpenMcdf.CompoundFile compoundFile = new CompoundFile(memoryStream);
            OpenMcdf.CFStream stream = compoundFile.RootStorage.GetStream("Package");
            byte[] packageData = stream.GetData();
            using (MemoryStream packageDataStream = new MemoryStream(packageData))
            {
                Document word = new Document(packageDataStream);
                word.Save("Document.docx", Aspose.Words.SaveFormat.Docx);                                    
            }
        }

@youzi,

I suggest you to please visit this documentation link to serve the purpose on your end. I hope this will be helpful.

Many Thanks,

Mudassir Fayyaz