none
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?


    Sample:

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

    <w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
        <w:r>
            <w:rPr>
                     <w:sz w:val="28" />
            </w:rPr>
            <w:t>Hello World</w:t>
        </w:r>
    </w:p>

    Thanks & Regards,

    Vikash

     

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

    Thanks...Vikash

     

     

    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>"

    element.Add(HighlightMarkup)

     

    End If

     

    Next

    Saturday, October 23, 2010 4:57 PM