Sign In  Sign Up Live-Chat

How to extract OLE objects from PowerPoint documents using Aspose.Slides?

Last post 05-15-2008, 1:05 PM by starkslaw1. 10 replies.
Sort Posts: Previous Next
  •  04-10-2008, 1:47 PM 121657

    How to extract OLE objects from PowerPoint documents using Aspose.Slides?

    Attachment: Present (inaccessible)

    Aspose.Slides is a file management component that can help you read/write/manipulate the PowerPoint documents.

     

    You can also extract OLE objects from PowerPoint documents using Aspose.Slides. For example, I have attached a sample application here along with solution/project in C#, it basically reads the source ppt and extracts the OLE objects (excel chart and pdf document) from it and write it to C: drives.

     

    Hopefully, it will be helpful for you.

     

    You can ask any of your questions regarding Aspose.Slides from the Aspose.Slides forum.

    http://www.aspose.com/community/forums/aspose.slides-for-.net-java-and-reporting-services/109/showforum.aspx

     

    C# Code

    -------------------------------------------------------------

    //Read the source ppt file

    string sourcePath = @"..\..\..\source.ppt";

    Presentation srcPres = new Presentation(sourcePath);

    //Get the first slide

    Slide sld = srcPres.GetSlideByPosition(1);

    //Output file id

    int fid = 0;

    //Extract all ole objects

    foreach (Shape shp in sld.Shapes)

    {

    //oof will not be null, if shape is ole object frame

    OleObjectFrame oof = shp as OleObjectFrame;

    if (oof != null)

    {

    //Check the class

    string objName = oof.ObjectClassName;

    //decide extension

    //if it is excel, set it as .xls

    //if it is pdf, set it as .pdf

    string ext = "";

    if (objName.Contains("Microsoft Excel Chart") == true)

    ext = ".xls";

    else

    if (objName.Contains("Adobe Acrobat 7.0 Document") == true)

    ext = ".pdf";

    //Now extract the data and write it to file

    FileStream fout = new FileStream("c:\\outOLE" + fid + ext, FileMode.Create, FileAccess.Write);

    fout.Write(oof.ObjectData, 0, oof.ObjectData.Length);

    fout.Close();

    //increment fid

    fid++;

    }

    }


    Many Thanks and Kind Regards,

    Shakeel Faiz
    Support Engineer
    Aspose Tyumen Team
     
  •  04-12-2008, 3:22 PM 121958 in reply to 121657

    Re: How to extract OLE objects from PowerPoint documents using Aspose.Slides?

    What is the equivalent of this line:

    OleObjectFrame oof = shp as OleObjectFrame;


    in VB.NET?

     
  •  04-12-2008, 3:26 PM 121959 in reply to 121958

    Re: How to extract OLE objects from PowerPoint documents using Aspose.Slides?

    I've tried this:

    Dim oof As Aspose.Slides.OleObjectFrame = CType(shape, Aspose.Slides.OleObjectFrame)

    but no luck.

     
  •  04-13-2008, 2:30 PM 121994 in reply to 121959

    Re: How to extract OLE objects from PowerPoint documents using Aspose.Slides?

    Attachment: Present (inaccessible)

    I have updated the thread with VB.NET code, which works exactly the same as C# code in previous post.

     

    VB.NET

    'Read the source ppt file

    Dim sourcePath As String = "..\..\..\source.ppt"

    Dim srcPres As Presentation = New Presentation(sourcePath)

    'Get the first slide

    Dim sld As Slide = srcPres.GetSlideByPosition(1)

    'Output file id

    Dim fid As Integer = 0

    'Extract all ole objects

    For Each shp As Shape In sld.Shapes

    If TypeOf shp Is OleObjectFrame Then

    Dim oof As OleObjectFrame = shp

    'Check the class

    Dim objName As String = oof.ObjectClassName

    'Decide the extension

    'if it is excel, set it as .xls

    'if it is pdf, set it as .pdf

    Dim ext As String = ""

    If objName.Contains("Microsoft Excel Chart") = True Then

    ext = ".xls"

    ElseIf objName.Contains("Adobe Acrobat 7.0 Document") = True Then

    ext = ".pdf"

    End If

    'Now extract the data and write it to file

    Dim fout As FileStream

    fout = New FileStream("c:\outOLE" & fid & ext, FileMode.Create, FileAccess.Write)

    fout.Write(oof.ObjectData, 0, oof.ObjectData.Length)

    fout.Close()

    'increment fid

    fid = fid + 1

    End If

    Next


    Many Thanks and Kind Regards,

    Shakeel Faiz
    Support Engineer
    Aspose Tyumen Team
     
  •  04-14-2008, 9:31 AM 122114 in reply to 121994

    Re: How to extract OLE objects from PowerPoint documents using Aspose.Slides?

    I am using .NET 1.0 and this code does not work.  This line:

    Dim oof As Aspose.Slides.OleObjectFrame = shp

    gives me this error: "Value of type 'Aspose.Slides.Shape' cannot be converted to 'Aspose.Slides.OLEObjectFrame'"
     
  •  04-14-2008, 1:22 PM 122178 in reply to 122114

    Re: How to extract OLE objects from PowerPoint documents using Aspose.Slides?

    Try this one

    Dim oof As OleObjectFrame = CType(shp, OleObjectFrame)


    Many Thanks and Kind Regards,

    Shakeel Faiz
    Support Engineer
    Aspose Tyumen Team
     
  •  04-15-2008, 7:56 AM 122341 in reply to 122178

    Re: How to extract OLE objects from PowerPoint documents using Aspose.Slides?

    If you check my post three messages up, that's exactly what I tried already.  Any other thoughts?
     
  •  04-15-2008, 11:06 AM 122396 in reply to 122341

    Re: How to extract OLE objects from PowerPoint documents using Aspose.Slides?

    Hello,

    Everything should work fine if you didn't forget to check shape type before this line like shown in the VB example also 3 messages up:

    If TypeOf shp Is OleObjectFrame Then
       Dim oof As OleObjectFrame = CType(shp, OleObjectFrame)

    Alexey Zhilin
    Team Leader
    Aspose Tyumen Team
    About Us
    Contact Us
     
  •  04-15-2008, 12:07 PM 122407 in reply to 122396

    Re: How to extract OLE objects from PowerPoint documents using Aspose.Slides?

    This is not a run-time error, I am not able to compile my code at all when trying to cast this value.

    I am using MDE 2002 v 7.0.9955, .NET 1.0
     
  •  04-15-2008, 12:33 PM 122416 in reply to 122396

    Re: How to extract OLE objects from PowerPoint documents using Aspose.Slides?

    Figured it out.  You have to instantiate shp as a generic object:

    Dim shp As Object

    That way, you can cast it as anything you like.  This is most likely an issue with .NET 1.0
     
  •  05-15-2008, 1:05 PM 127276 in reply to 121657

    Re: How to extract OLE objects from PowerPoint documents using Aspose.Slides?

    Thanks. We'll give it a try.
     
View as RSS news feed in XML