I am using the Office Developer Tools for Visual Studio 2013 in C#. Ever since Word 2007, adding a "\n" character adds a paragraph break (which adds more space than the line break in Word). How can I add a line break to a document? I've tried "\n", "\r", and "\r\n" all of which seem to add a paragraph break.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
It turns out that Word uses Vertical Tabs for its line breaks. I was able to add them using the "\v" character to ranges. See What is a vertical tab? for more details.
回答2:
I've tried to use several items such as:
</br>
\n\r
\u2028\n
<w:br/>
which they don't work but when simply replace desired character with <br/>
it works very well!
I have to mention that i use VS2013, and MS Office2016.
回答3:
Word is using the "Line Separator" and "Paragraph Separator" Unicode characters, with codepoints 2028 and 2029, respectively, to represent those respective kinds of breaks.
Use the Unicode character "Line Separator," expressed in C# as '\u2028'
. Use this in combination with the newline character \n
.
回答4:
That works for me: stringBuilder.Append("<w:br/>");