ReplaceText don't preserve original formatting

Nov 18, 2015 at 8:28 AM
This is the original text:
Bleibende Invalidität durch Unfall €
Ärztliche Spesen €

Für Kasko km:
Versicherungssumme pro Fahrzeug €

This is the code:
paragraph.ReplaceText(tagToRewrite, newValue);

This is the incorrect result:
Bleibende Invalidität durch Unfall € Ärztliche Spesen € Für Kasko km: Versicherungssumme pro Fahrzeug €

As you can see, the formatting result, is different.
I see that in 2011 the problem was fixed (http://docx.codeplex.com/SourceControl/changeset/62851), but in the last release (v1.0.0.19) we have this problem again.

Is there some work around?
Thanks
Nov 18, 2015 at 2:42 PM
Resolved!

i have downloaded a source code and in "HelperFunctions" class there is a "internal static List<XElement> FormatInput(string text, XElement rPr)" mothod.
This method loop every char of the string, but test only /t and /n, BUT NOT /r. In my text there is: "Bleibende Invalidität durch Unfall € /r Ärztliche Spesen €" ecc.
So, if i add case '\r': in existing case '\n': the formatting is ok because cerate a new run.
                case '\r':
                case '\n':
                    if (sb.Length > 0)
                    {
                        XElement t = new XElement(DocX.w + "t", sb.ToString());
                        Novacode.Text.PreserveSpace(t);
                        newRuns.Add(new XElement(DocX.w + "r", rPr, t));
                        sb = new StringBuilder();
                    }
                    newRuns.Add(new XElement(DocX.w + "r", rPr, breakRun));
                    break;
For Madboy Developer: test if my solution is correct, and if is ok, I think that the next release should contain this change.
Regards
Marked as answer by gianx10 on 11/18/2015 at 6:42 AM
Developer
Nov 18, 2015 at 8:29 PM
Commited. Thank you. Seems legit :-) Please verify.