简体   繁体   中英

OpenXML SDK add line break or use multiline string in replace (regex)

I am replacing my word document content using OpenXML and with the help of regex detecting words in my document and replacing them with new sentences but the problem is that when I have a long string that contains line breaks the work document displays it as a single line. I have searched everywhere and tried all possible solutions. I even tried this

**

string pre = "<w:p><w:r><w:t>";
        string post = "</w:t></w:r></w:p>";
        string lineBreak = "<w:br />";
        string test = pre + "First Line" + lineBreak + "Second Line" + post;
        //
        Regex regexText1 = new Regex("Question");
        docText = regexText1.Replace(docText, @test);

**

But the result shows long tabs between the text of the first line. Please provide a solution. Word Document Result

Try this one

    string pre = "<w:p><w:r><w:t>";
        string lineBreak ="</w:t><w:br /><w:t>"
                string post = "</w:t></w:r></w:p>";
                string test = pre + "First Line" + lineBreak + "Second Line" + post;
//
        Regex regexText1 = new Regex("Question");
        docText = regexText1.Replace(docText, @test);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM