none
PowerPoint Interop - How to access Chart out of a shape? RRS feed

  • Question

  • I am working in an office automation tool to process PowerPoint documents, where I am facing an issue in formatting Chart.

     

    I am using the following assemblies for formatting the Presentation

    Microsoft.Office.Interop.PowerPoint  Version: 12.0.0.0

    Microsoft.Office.Interop.Graph Version: 12.0.0.0

    Requirement is to apply some styles like Legend location, color, font etc to the Chart exists in the presentation.

     

    I am able to verify the Shape like

    shape.HasChart == MsoTriState.msoTrue

    But not able to get the Chart object out of the shape

     

    Tried the following code, but received OLEFormat exception

    Graph.Chart chart = (Graph.Chart)shape.OLEFormat.Object

     

    Thanks in advance for your help.


    Assistant Consultant

    Thursday, April 4, 2013 11:42 AM

Answers

  • Hi Ambily

    The code snippets you show are for Charts created with the new Office 2007 charting engine. That is not compatible with MS Graph, the assembly you're linking in - that uses the old charting engine from Office 97-2003. MS Graph has only limited formatting capability; the new Chart engine provides much more functionality. Must you use MS Graph?

    Note that PowerPoint 2007 will only have full access to the new charting engine APIs if you have the Service Packs installed and use the PowerPoint and Office PIAs in the GAC (from the COM not the .NET tab when adding a Reference). You may also find this discussion useful:
    http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/a93de40e-3f89-489b-93a1-bf9e387c3bed


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Ambily Friday, April 5, 2013 4:45 AM
    Thursday, April 4, 2013 3:50 PM
    Moderator

All replies

  • Hi Ambily

    The code snippets you show are for Charts created with the new Office 2007 charting engine. That is not compatible with MS Graph, the assembly you're linking in - that uses the old charting engine from Office 97-2003. MS Graph has only limited formatting capability; the new Chart engine provides much more functionality. Must you use MS Graph?

    Note that PowerPoint 2007 will only have full access to the new charting engine APIs if you have the Service Packs installed and use the PowerPoint and Office PIAs in the GAC (from the COM not the .NET tab when adding a Reference). You may also find this discussion useful:
    http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/a93de40e-3f89-489b-93a1-bf9e387c3bed


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Ambily Friday, April 5, 2013 4:45 AM
    Thursday, April 4, 2013 3:50 PM
    Moderator
  • Hi Cindy

    Thanks for the above reply. This was working till last day and after that I have uninstalled Office 2010 for testing purpose. Now I have Office 2007 SP1 and the above solution is not working.

    I have add the reference from COM tab and tried to access the Chart out of the shape using various ways like

    1. trying to convert to Graph.Chart , received OLE object exception

    2. trying to access shape.Chart, no supported property

    How can I get the Chart reference in Office 2007 SP1?

    Thanks

    Ambily


    Assistant Consultant

    Sunday, April 14, 2013 2:33 PM
  • As mentioned in my previous reply, you need to install ALL the Service Packs for Office 2007. The charting engine APIs weren't included until much, much later. This also applies to any client machines to which you deploy your solution. You also need to update your PIA references as per my previous message.

    Cindy Meister, VSTO/Word MVP, my blog

    Sunday, April 14, 2013 3:09 PM
    Moderator