Mr. Cooper
Mr. Cooper

Reputation: 414

How to Replace a Line Break with a New Paragraph Using OpenXml

I have a set of documents that I replace placeholder text with text inputted by a user. A user has a list of words with definitions (data below is just an example). A tab separates the word from the definition. A new line is created for each new word/definition. Utilizing the OpenXmlRegex.Replace method in OpenXml PowerTools results in line breaks added in for new lines (<w:br />). It would be preferred if the new lines were actually new paragraphs to retain the hanging tab in the document.

Example:

        <w:p w:rsidRPr="######" w:rsidR="######" w:rsidP="######" w:rsidRDefault="######">
            <w:pPr>
                <w:rPr>
                    <w:rFonts w:eastAsia="Times New Roman" w:cs="Arial" />
                    <w:spacing w:val="-3" />
                </w:rPr>
            </w:pPr>
            <w:r>
                <w:rPr>
                    <w:rFonts w:eastAsia="Times New Roman" w:cs="Arial" />
                    <w:spacing w:val="-3" />
                </w:rPr>
                <w:t>Feline:</w:t>
            </w:r>
            <w:r>
                <w:rPr>
                    <w:rFonts w:eastAsia="Times New Roman" w:cs="Arial" />
                    <w:spacing w:val="-3" />
                </w:rPr>
                <w:tab />
            </w:r>
            <w:r>
                <w:rPr>
                    <w:rFonts w:eastAsia="Times New Roman" w:cs="Arial" />
                    <w:spacing w:val="-3" />
                </w:rPr>
                <w:t>relating to or affecting cats or other members of the cat family.</w:t>
            </w:r>
            <w:r>
                <w:rPr>
                    <w:rFonts w:eastAsia="Times New Roman" w:cs="Arial" />
                    <w:spacing w:val="-3" />
                </w:rPr>
                <w:br />
            </w:r>
            <w:r>
                <w:rPr>
                    <w:rFonts w:eastAsia="Times New Roman" w:cs="Arial" />
                    <w:spacing w:val="-3" />
                </w:rPr>
                <w:t>
Canine:</w:t>
            </w:r>
            <w:r>
                <w:rPr>
                    <w:rFonts w:eastAsia="Times New Roman" w:cs="Arial" />
                    <w:spacing w:val="-3" />
                </w:rPr>
                <w:tab />
            </w:r>
            <w:r>
                <w:rPr>
                    <w:rFonts w:eastAsia="Times New Roman" w:cs="Arial" />
                    <w:spacing w:val="-3" />
                </w:rPr>
                <w:t xml:space="preserve">relating to or resembling a dog or dogs.</w:t>
            </w:r>
            <w:r>
                <w:rPr>
                    <w:rFonts w:eastAsia="Times New Roman" w:cs="Arial" />
                    <w:spacing w:val="-3" />
                </w:rPr>
                <w:br />
            </w:r>
        </w:p>

Preferred Code:

       <w:p w:rsidRPr="######" w:rsidR="######" w:rsidP="######" w:rsidRDefault="######">
            <w:pPr>
                <w:rPr>
                    <w:rFonts w:eastAsia="Times New Roman" w:cs="Arial" />
                    <w:spacing w:val="-3" />
                </w:rPr>
            </w:pPr>
            <w:r>
                <w:rPr>
                    <w:rFonts w:eastAsia="Times New Roman" w:cs="Arial" />
                    <w:spacing w:val="-3" />
                </w:rPr>
                <w:t>Feline:</w:t>
            </w:r>
            <w:r>
                <w:rPr>
                    <w:rFonts w:eastAsia="Times New Roman" w:cs="Arial" />
                    <w:spacing w:val="-3" />
                </w:rPr>
                <w:tab />
            </w:r>
            <w:r>
                <w:rPr>
                    <w:rFonts w:eastAsia="Times New Roman" w:cs="Arial" />
                    <w:spacing w:val="-3" />
                </w:rPr>
                <w:t>relating to or affecting cats or other members of the cat family.</w:t>
            </w:r>
            <w:r>
                <w:rPr>
                    <w:rFonts w:eastAsia="Times New Roman" w:cs="Arial" />
                    <w:spacing w:val="-3" />
                </w:rPr>
            </w:r>
        </w:p>
        <w:p w:rsidRPr="######" w:rsidR="######" w:rsidP="######" w:rsidRDefault="######">
            <w:r>
                <w:rPr>
                    <w:rFonts w:eastAsia="Times New Roman" w:cs="Arial" />
                    <w:spacing w:val="-3" />
                </w:rPr>
                <w:t>
Canine:</w:t>
            </w:r>
            <w:r>
                <w:rPr>
                    <w:rFonts w:eastAsia="Times New Roman" w:cs="Arial" />
                    <w:spacing w:val="-3" />
                </w:rPr>
                <w:tab />
            </w:r>
            <w:r>
                <w:rPr>
                    <w:rFonts w:eastAsia="Times New Roman" w:cs="Arial" />
                    <w:spacing w:val="-3" />
                </w:rPr>
                <w:t xml:space="preserve">relating to or resembling a dog or dogs.</w:t>
            </w:r>
            <w:r>
                <w:rPr>
                    <w:rFonts w:eastAsia="Times New Roman" w:cs="Arial" />
                    <w:spacing w:val="-3" />
                </w:rPr>
            </w:r>
        </w:p>

Upvotes: 1

Views: 478

Answers (0)

Related Questions