2

I parse string to <![CDATA[{0}]]> as below

string a = "<![CDATA[put returns between \r\n paragraphs \n for linebreak add 2 spaces <br/> at end]]>"

After I read a document (.docx) by WordprocessingDocument.

string docText = null;
 using (StreamReader sr = new StreamReader(wordDoc.MainDocumentPart.GetStream()))
   {
      docText = sr.ReadToEnd();
   }

   docText = docText.Replace("needtochange", a);

 using (StreamWriter sw = new StreamWriter(wordDoc.MainDocumentPart.GetStream(FileMode.Create)))
   {
       sw.Write(docText);
}

As result is "put returns between paragraphs for linebreak add 2 spaces at end" at the same line. It does not effect.

Adrian
  • 8,271
  • 2
  • 26
  • 43
Englbach
  • 75
  • 8
  • 1
    Not sure I exactly understand, but I think you are saying that your `\r` `\n` is not creating line breaks in a Word document. That is right, it doesn't. [See if this helps you](https://stackoverflow.com/questions/51566826/openxmlsdk-insert-new-line-inside-of-a-run-element/51570989#51570989) – Crowcoder Aug 29 '18 at 10:49
  • Maybe something like this? https://stackoverflow.com/questions/2871887/inserting-newlines-in-word-using-openxml – LocEngineer Aug 29 '18 at 10:52

0 Answers0