private void TryFindTable() { if (BkmStart == null || BkmEnd == null) { return; } var table = BkmEnd.GetParent <Table>(); if (table != null) { Table = new WordDocumentTable(Doc, table); } }
private void ReplaceOneParagraph(string text) { var rProp = GetDefaultRunProperties(); if (IsOneParagraphText(text)) { if (BkmStart.PreviousSibling <Run>() == null && BkmEnd.ElementsAfter() != null && BkmEnd.ElementsAfter().All(e => e.GetType() != typeof(Run))) { BkmStart.Parent.RemoveAllChildren <Run>(); } else { var list = GetBookmarkElements().ToList(); var trRun = list .Where(rp => rp.GetType() == typeof(Run) && ((Run)rp).RunProperties != null) .Select(rp => ((Run)rp).RunProperties).FirstOrDefault(); if (trRun != null) { rProp = (RunProperties)trRun.Clone(); } for (var n = list.Count; n > 0; n--) { list[n - 1].Remove(); } } var nRun = new Run(); if (rProp != null) { nRun.RunProperties = (RunProperties)rProp.Clone(); } var nText = new Text { Text = text }; nRun.Append(nText); BkmStart.InsertAfterSelf(nRun); } else { var paraProp = (ParagraphProperties)BkmStart.GetParent <Paragraph>().ParagraphProperties.Clone(); BkmStart.Parent.Remove(); InsertMultiLineText(text, SiblingElement, paraProp, rProp); } }
private Tuple <BookmarkStart, BookmarkEnd> GetBookmarkCopy() { if (BkmStart == null || BkmEnd == null) { return(null); } int id; if (!int.TryParse(BkmStart.Id, out id)) { return(null); } var newBkmStart = (BookmarkStart)BkmStart.Clone(); newBkmStart.Name = BkmStart.Name + "_copy"; newBkmStart.Id = (id + 1000).ToString(); var newBkmEnd = (BookmarkEnd)BkmEnd.Clone(); newBkmEnd.Id = newBkmStart.Id; return(new Tuple <BookmarkStart, BookmarkEnd>(newBkmStart, newBkmEnd)); }