The solution is to replace the newline characters with OpenXML Line Breaks.
I found this method on Stack Overflow which solves the problem:
////// Parses the string and replaces New Line chars with OpenXML line breaks /// /// /// public static void ParseForOpenXML(ref Run run, string textualData) { string[] newLineArray = { Environment.NewLine, "\n" }; string[] textArray = textualData.Split(newLineArray, StringSplitOptions.None); bool first = true; foreach (string line in textArray) { if (!first) { run.Append(new Break()); } first = false; Text txt = new Text(); txt.Text = line; run.Append(txt); } }
No comments:
Post a Comment