Question

I have a pretty basic question regarding the openxml sdk. I want to process pptx documents.

In my c# code from slideMaster1.xml I want to get a list of every XMLNode where the node's type is p:cNvPr because i want to store their values in a list of strings.

How can i do that?

Was it helpful?

Solution

Zoltan, The 'p:cNvPr' nodes are Non-Visual Drawing Properties which specifies non-visual canvas properties. See the MSDN documentation for more details.

I wrote a small windows forms app that will open a power point and display the name attributes for all of the non-visual drawing properties for all of the layouts in the Master using the sdk. Please see screen shot below and link for zip of the Solution.

enter image description here

The code basically does the following:

foreach (var slideMasterPart in PresentationPart.SlideMasterParts)
{
    foreach (var layouts in slideMasterPart.SlideLayoutParts)
    {
    get each of the layouts.SlideLayout.CommonSlideData.ShapeTree.Descendants<NonVisualDrawingProperties>();
                and put the name attribute to the grid.
    }
}

OTHER TIPS

Not sure, but I think LinqToXml can handle that without openxml.

string[] values = XElement.Load("slideMaster1.xml")
                       .Descendants("p:cNvPr")
                       .Select(x => (string)x)
                       .ToArray();

It may cough on the p: as I'm not sure how it'll handle the namespace. If you give a sample of your xml, I could test it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top