Back to Blog
ObjRange.Text = "Regular text aligned center\nwith something on the next line" Environment.NewLine ObjRange.Text = "Regular text aligned left" Environment.NewLine ObjRange.Text = "Bold text aligned center" Environment.NewLine Generally, assign text content, then format the Range. If numerous paragraphs should have the same formatting, they can be combined.Įnvironment.NewLine and \n can be used interchangeably. So if you have bold in the middle of a line, that's a separate step. The following code snippet is my preference: collapsing the Range for each step (think of it like pressing the right-arrow key to "collapse" a selection to a point), rather than mixing Add, InsertAfter and similar methods.įor each change of formatting the Range must be "collapsed". There's more than one way to achieve a goal of this nature. The key to working with content in Word documents is to understand how to work with Range objects. ![]() So, my question is - how to add text from c# to a newly created word document with the right properties, so the result looks like this: I'm assuming that text in is not supposed to act like that, or text should be added in some other way, but I'm failing to find any good information on how to do this. The code above creates a Word document and writes text to it, but it looks like this: ![]() = "Regular text aligned left, with some Bold text here\nand some regular text on next line" = "Regular text aligned center\nwith something on the next line" Word.Application objWord = new Word.Application()
0 Comments
Read More
Leave a Reply. |