Add an element to the existing Paragraph RRS feed

  • Question

  • Hi All,

    Once again I need your help. If I want to add some attribute to the paragraph text such as increase the font size or give background color, I would add <w:rPr><w:sz w:val = "28"></w:rPr> or <w:rPr><w:highlight w:val = "yellow"></w:rPr> within <w:r>.

    My questions are,

    1. What are steps (all) required to insert<w:rPr> in the existing open xml doc?

    2. Is there some article to guide me?


    I want to add <w:rPr> within the <w:r> element. 

    <w:p xmlns:w="">
                     <w:sz w:val="28" />
            <w:t>Hello World</w:t>

    Thanks & Regards,



    Friday, October 22, 2010 10:54 AM

All replies

  • I did some homework..and thought of implementing in the following way:

    1.> Query each run element.

    2.> If the run element contains word (Hello) then add the HighlightMarkup within the Run.

    <Code is shared below>

    But its NOT working out..

    Experts..request you to pls advice..




    Dim paragraphs = _


    From para In xDoc.Root.<w:body>...<w:r> _


    Let styleNode As XElement = para.<w:pPr>.<w:pStyle>.FirstOrDefault _


    Select New With { _

    .ParagraphNode = para, _

    .StyleName = GetStyleOfParagraph(styleNode, defaultStyle) _




    For Each p In paragraphs


    If p.ParagraphNode.ToString.Contains("Hello") Then


    Dim element As XElement = p.ParagraphNode


    Dim HighlightMarkup As String = "<w:rPr><w:highlight w:val=""yellow""/></w:rPr>"



    End If



    Saturday, October 23, 2010 4:57 PM