[英]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.我正在使用 OpenXML 替换我的 word 文档内容,并借助正则表达式检测文档中的单词并用新句子替换它们,但问题是当我有一个包含换行符的长字符串时,工作文档将其显示为单行. 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
Word 文档结果
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.