public static void ReplaceNewLinesWithBreaks(XElement xElem)
{
if (xElem == null) return;
var textWithBreaks = xElem.Descendants(W.t).Where(t => t.Value.Contains("\r\n"));
foreach (var textWithBreak in textWithBreaks)
{
var text = textWithBreak.Value;
var split = text.Replace("\r\n", "\n").Split(new[] { "\n" }, StringSplitOptions.None);
textWithBreak.Value = string.Empty;
foreach (var s in split)
{
textWithBreak.Add(new XElement(W.t, s));
textWithBreak.Add(new XElement(W.br));
}
textWithBreak.Descendants(W.br).Last().Remove();
}
}
But when it insert br - it don't copy style for element (like padding). How can I add real paragraph ? I tried make like this, but it's breaking document:
public static void ReplaceNewLinesWithBreaks(XElement xElem)
{
if (xElem == null) return;
var textWithBreaks = xElem.Descendants(W.t).Where(t => t.Value.Contains("\r\n"));
foreach (var textWithBreak in textWithBreaks)
{
var text = textWithBreak.Value;
var split = text.Replace("\r\n", "\n").Split(new[] { "\n" }, StringSplitOptions.None);
textWithBreak.Value = string.Empty;
foreach (var s in split)
{
xElem.Add(new XElement(W.p, new XElement(W.r, new XElement(W.t, s)))); //here changed code
}
}
}
Maybe I can get some true parent element, where I can add those new Paragraphs ?
What if I need to insert Paragraph on new line ?
Early here was issue #2 , and was addes code:
But when it insert br - it don't copy style for element (like padding). How can I add real paragraph ? I tried make like this, but it's breaking document:
Maybe I can get some true parent element, where I can add those new Paragraphs ?
Thank you!!