Inserting newlines in Word using OpenXML

前端 未结 4 596
轻奢々
轻奢々 2020-11-30 04:34

I am using openxml WordProcessingDocument to open a Word template and replace placeholder x1 with a string. This works fine unless I need the string to contain a newline.

4条回答
  •  爱一瞬间的悲伤
    2020-11-30 05:12

    To insert newlines, you have to add a Break instance to the Run.

    Example:

    run.AppendChild(new Text("Hello"));
    run.AppendChild(new Break());
    run.AppendChild(new Text("world"));
    

    The XML produced will be something like:

    
      Hello
      
      world
    
    

提交回复
热议问题