Ejemplo n.º 1
0
        // Get the placeholders in the template and store a pristine copy of the template.
        internal void Initialize()
        {
            OpenXmlCompositeElement templateElement = null;

            if (Code.Contains("AppendParagraph"))
            {
                templateElement = Placeholder.GetParent <Paragraph>();
            }
            else if (Code.Contains("AppendRow"))
            {
                templateElement = Placeholder.GetParent <TableRow>();
            }

            _newElement      = templateElement;
            _placeholders    = GetPlaceholders(templateElement);
            _templateElement = templateElement.Clone() as OpenXmlCompositeElement;
        }
Ejemplo n.º 2
0
        internal void Append <T>() where T : OpenXmlCompositeElement
        {
            // Clone _newElement, because we're going to use the placeholders currently in it again.
            var clonedNewElement = _newElement.Clone() as T;

            if (_lastElement == null)
            {
                // First call to Append: _newElement points to the original template.
                _lastElement = _newElement.InsertAfterSelf(clonedNewElement);

                // Remove the original template from the document.
                _newElement.Remove();
            }
            else
            {
                // Subsequent calls to Append.
                _lastElement = _lastElement.InsertAfterSelf(clonedNewElement);
            }

            // Create a pristine new element and initialize it with the placeholders.
            _newElement = _templateElement.Clone() as T;
            SetPlaceholders(_newElement);
        }