public override void Process() { base.Process(); var element = TextTag.TagNode; var text = DataReader.ReadText(TextTag.Expression); XElement parent = element.Parent; if (parent.Name == WordMl.TableRowName) { parent = element.Element(WordMl.SdtContentName).Element(WordMl.TableCellName); } var textElement = DocxHelper.CreateTextElement(element, parent, text); var result = this.CreateDynamicContentTags ? DocxHelper.CreateDynamicContentElement(new[] { textElement }, this.TextTag.TagNode, this.DynamicContentLockingType) : textElement; if (element.Parent.Name != WordMl.TableRowName) { element.AddBeforeSelf(result); } else { var cell = new XElement(WordMl.TableCellName, result); cell.AddFirst(element.Descendants(WordMl.TableCellPropertiesName)); element.AddBeforeSelf(cell); } element.Remove(); }
private XElement ProcessCell(TableElement tableElement, XElement previous, string text) { var isInnerCell = tableElement.HasCell(); var currentCell = this.CurrentCell(tableElement); previous = this.ProcessStaticCells(tableElement, previous); var parent = isInnerCell ? currentCell: tableElement.StartTag.Parent; var result = DocxHelper.CreateTextElement( tableElement.StartTag, parent, text); if (!isInnerCell) { tableElement.StartTag.AddAfterSelf(result); } else { if (currentCell.Elements(WordMl.ParagraphName).Any()) { currentCell.Elements(WordMl.ParagraphName).Remove(); } currentCell.Add(result); } if (previous != null && !previous.Equals(currentCell)) { currentCell.Remove(); previous.AddAfterSelf(currentCell); } else if (previous == null) { var parentRow = isInnerCell ? tableElement.StartTag.Parent : currentCell.Parent; currentCell.Remove(); parentRow.Add(currentCell); } return(currentCell); }
private XElement ProcessElements(IEnumerable <RepeaterElement> elements, DataReader dataReader, XElement start, XElement parent, int index, ref XElement endIfElement, ref XElement nestedRepeaterEndElement, ref XElement currentEndItemTable, bool nested = false) { XElement result = null; XElement previous = start; //if ((parent != null) && (!parent.Name.Equals(WordMl.TableCellName))) //{ elements = elements.Where(el => !this.IsItemRepeaterElement(el.XElement)).ToList(); //} foreach (var repeaterElement in elements) //elements.Where(el => !this.IsItemRepeaterElement(el.XElement)).ToList()) { if (nestedRepeaterEndElement != null) { if (repeaterElement.XElement.Equals(nestedRepeaterEndElement)) { nestedRepeaterEndElement = null; } continue; } if (currentEndItemTable != null) { if (repeaterElement.XElement.Equals(currentEndItemTable)) { currentEndItemTable = null; } continue; } if (repeaterElement.IsEndItemIf /*&& repeaterElement.XElement.Equals(endIfElement)*/) { //endIfElement = null; if (repeaterElement.XElement.Equals(endIfElement)) { endIfElement = null; } continue; } if ((endIfElement != null) && !repeaterElement.XElement.Name.Equals(WordMl.ParagraphName)) { continue; } if (repeaterElement.IsItemIf) { this.ProcessItemIfElement(repeaterElement, dataReader, ref endIfElement); continue; } if (repeaterElement.IsItemTable) { /*currentEndItemTable = RepeaterParser.FindEndTag(repeaterElement.XElement, "itemtable", * "enditemtable");*/ currentEndItemTable = repeaterElement.EndTag; } /* * if (repeaterElement.IsEndItemTable /*|| (repeaterElement.XElement.Name.Equals(WordMl.TableName) && repeaterElement.XElement.Descendants().Any(el => el.IsSdt()))) * { * continue; * }*/ if (repeaterElement.IsItemHtmlContent) { result = HtmlContentProcessor.MakeHtmlContentProcessed(repeaterElement.XElement, dataReader.ReadText(repeaterElement.Expression), true); } else if (repeaterElement.IsItemTable) { result = ItemTableGenerator.ProcessItemTableElement(repeaterElement.StartTag, repeaterElement.EndTag, dataReader); if (nested) { previous.AddAfterSelf(result); previous = result; result = null; } } else if (repeaterElement.IsItemRepeater) { var itemRepeaterTag = new ItemRepeaterTag() { StartItemRepeater = repeaterElement.StartTag, EndItemRepeater = repeaterElement.EndTag, Source = repeaterElement.Expression }; var itemRepeaterGenerator = new ItemRepeaterGenerator(); previous = itemRepeaterGenerator.Generate(itemRepeaterTag, dataReader.GetReaders(repeaterElement.Expression), previous, parent, true); result = null; nestedRepeaterEndElement = repeaterElement.EndTag; } else if (repeaterElement.IsIndex) { result = DocxHelper.CreateTextElement(repeaterElement.XElement, repeaterElement.XElement.Parent, index.ToString(CultureInfo.CurrentCulture)); } else if (repeaterElement.IsItem && repeaterElement.HasExpression) { result = DocxHelper.CreateTextElement(repeaterElement.XElement, repeaterElement.XElement.Parent, dataReader.ReadText(repeaterElement.Expression), dataReader.ReadAttribute(repeaterElement.Expression, "style")); } else { var element = new XElement(repeaterElement.XElement); element.RemoveNodes(); result = element; if (repeaterElement.HasElements) { var parsedLastElement = this.ProcessElements(repeaterElement.Elements, dataReader, previous, result, index, ref endIfElement, ref nestedRepeaterEndElement, ref currentEndItemTable, true); if (repeaterElement.Elements.Any(re => re.IsItemTable) || repeaterElement.Elements.Any(re => re.IsItemRepeater && !ItemRepeaterGenerator.CheckInlineWrappingMode(re.StartTag, re.EndTag))) { previous = parsedLastElement; result = null; } } else { element.Value = repeaterElement.XElement.Value; } } if (result != null) { if (!nested) { previous.AddAfterSelf(result); previous = result; } else { parent.Add(result); } } } return(result ?? previous); }