码迷,mamicode.com
首页 > 其他好文 > 详细

OpenXmlElement Class

时间:2020-02-26 01:17:32      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:where   create   body   cti   aging   static   adk   bsp   cas   

https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.openxmlelement?view=openxml-2.8.1

Represents a base class that all elements in an Office Open XML document derive from. Represents a base class for all elements in an Office Open XML document.

1 public abstract class OpenXmlElement : ICloneable, System.Collections.Generic.IEnumerable<DocumentFormat.OpenXml.OpenXmlElement>
Inheritance
OpenXmlElement
Derived
Implements

Examples

The following code example shows how to access elements at the same level in a word-processing document. The test file used in the example contains the text “OpenXml Element.”

using System;  
using System.Collections.Generic;  
using System.Linq;  
using DocumentFormat.OpenXml.Packaging;  
using DocumentFormat.OpenXml.Wordprocessing;  
  
namespace OpenXmlElement  
{  
    class Program  
    {  
        // This code example shows how to access elements at the same level    
        // in a word-processing document.   
        // The example is using a file that contains the text "OpenXml Element."  
        static void Main(string[] args)  
        {  
            string fileName = @"C:\Users\Public\Documents\AccessElementsSameLevel.docx";  
            using (WordprocessingDocument wordprocessingDocument =   
                WordprocessingDocument.Open(fileName, false))  
            {  
                // Create a Body object.  
                DocumentFormat.OpenXml.Wordprocessing.Body body =  
                    wordprocessingDocument.MainDocumentPart.Document.Body;  
  
                // Create a Paragraph object.  
                DocumentFormat.OpenXml.Wordprocessing.Paragraph firstParagraph =  
                    body.Elements<Paragraph>().FirstOrDefault();  
  
                // Get the first child of an OpenXmlElement.  
                 DocumentFormat.OpenXml.OpenXmlElement firstChild = firstParagraph.FirstChild;  
                IEnumerable<Run> elementsAfter =  
                    firstChild.ElementsAfter().Where(c => c is Run).Cast<Run>();  
  
                // Get the Run elements after the specified element.  
                Console.WriteLine("Run elements after the first child are: ");  
                foreach (DocumentFormat.OpenXml.Wordprocessing.Run run in elementsAfter)  
                {  
                    Console.WriteLine(run.InnerText);  
                }  
                Console.ReadKey();  
            }  
        }  
    }  
}  
// Output:  
// Run elements after the first child are:  
// OpenXml  
//  Element

 

OpenXmlElement Class

标签:where   create   body   cti   aging   static   adk   bsp   cas   

原文地址:https://www.cnblogs.com/ein-key5205/p/12364803.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!