简体   繁体   中英

Openxml 2.0 xml processing

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?

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.

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 .

在此处输入图片说明

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.
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM