Search code examples
c#interoppowerpointopenxml

How to get SmartArt information (text,name,type)from a slide?


I have to find following information from a smart art. SmartArt type,SmartArt Name and the text in itenter image description here

from the above image I want to find the below information

  1. type: Hierarchy.
  2. name: Organizational chart.
  3. text: Madan4.

with or with out using interop Till now by using OpenXML I can able to get only the text of a smart art.

var diagramDataPartsList = slidePart.DiagramDataParts;
if (diagramDataPartsList.Count() > 0)
{
    foreach (var diagramDataParts in diagramDataPartsList)
    {
        var text = diagramDataParts.DataModelRoot.PointList.InnerText;
        if (!string.IsNullOrEmpty(text))
        {
            Console.WriteLine(text.ToString());    
        }
    }
}

Solution

  • I got my answer from here and the answer is

    if (shape.HasSmartArt == MsoTriState.msoTrue)
    {
        var val1 = shape.SmartArt;
        string name = val1.Layout.Name;
        string category = val1.Layout.Category;
        string text1 = "";
        foreach (SmartArtNode node in val1.AllNodes)
        {
            text1 += node.TextFrame2.TextRange.Text;
        }
        Console.WriteLine("Smartart : {0} \tCategory : {1}\t Name : {2} text : {3}", (i++).ToString(), category, name, text1);
    }