2012-08-13 25 views
5

Word'ü Kullanma Standart bir.doc ile bir test olarak bir Docx oluşturdum. Merhaba dünya seviyesi karmaşıklığı.Açık XML: Word - "Heading1" stili olarak işaretlenen tüm Paragrafları alma

Word'de "Heading1" style ile biçimlendirilmiş olan all the paragraphs almak istiyorum.

Tüm paragrafları alabilirim, ancak Heading1'e nasıl filtre uygulayacağımı bilmiyorum. Ben boş istisna olsun

using (var doc = WordprocessingDocument.Open(documentFileName, false)) 
{ 
    paragraphs = doc.MainDocumentPart.Document.Body 
        .OfType<Paragraph>().ToList(); 
} 

cevap

8
[Test] 
    public void FindHeadingParagraphs() 
    { 

     var paragraphs = new List<Paragraph>(); 

     // Open the file read-only since we don't need to change it. 
     using (var wordprocessingDocument = WordprocessingDocument.Open(documentFileName, false)) 
     { 
      paragraphs = wordprocessingDocument.MainDocumentPart.Document.Body 
       .OfType<Paragraph>() 
       .Where(p => p.ParagraphProperties != null && 
          p.ParagraphProperties.ParagraphStyleId != null && 
          p.ParagraphProperties.ParagraphStyleId.Val.Value.Contains("Heading1")).ToList(); 
     } 
    } 
+0

, sadece ekledi:! P.ParagraphProperties.ParagraphStyleId = null && – Kiquenet

İlgili konular