private void RemoveCC(MainDocumentPart mainPart, string contentControlTag) { SdtRun contentControl = mainPart.Document.Body.Descendants <SdtRun>().Where(r => r.SdtProperties.GetFirstChild <Tag>().Val == contentControlTag).SingleOrDefault(); var breaks = contentControl.Parent.Descendants <Break>(); foreach (var item in breaks) { item.Remove(); } contentControl.Remove(); }
public static Run ReplaceToRun(this SdtRun Run, string?Content = null) { var run = Run.SdtContentRun !.GetFirstChild <Run>() !; run.Remove(); if (Content is not null) { run.Text(Content); } Run.InsertAfterSelf(run); Run.Remove(); return(run); }