示例#1
0
        public IDocumentBuilder Placeholder(string placeholderName, Action <IDocumentContextBuilder> options, bool preservePlaceholder = true)
        {
            var documentPlaceholders = DocumentPlaceholder.Get(Document, placeholderName);

            foreach (var documentPlaceholder in documentPlaceholders)
            {
                ClearBetweenElements(documentPlaceholder.Opening, documentPlaceholder.Closing);
            }

            SaveDocument();

            foreach (var documentPlaceholder in documentPlaceholders)
            {
                var builder = new DocxDocumentPlaceholderContextBuilder(Document, documentPlaceholders.Any() == false
                                                                                                        ? new RunProperties()
                                                                                                        : documentPlaceholder.Opening.RunProperties);
                options(builder);
                foreach (var contentElement in builder.AggregatedContent)
                {
                    documentPlaceholder.Closing.InsertBeforeSelf(contentElement.CloneElement());
                }
                if (preservePlaceholder == false)
                {
                    documentPlaceholder.Remove();
                }
            }

            SaveDocument();

            return(this);
        }
示例#2
0
        public void PlaceholderGettingWhichNotExistsReturnsEmpty()
        {
            using (var document = new DocxDocument(Resources.WithMainContentTag))
            {
                var placeholders = DocumentPlaceholder.Get(document.GetWordDocument(), "NON_EXISTING");

                Assert.IsEmpty(placeholders);
            }
        }
示例#3
0
        public void ManyPlaceholdersGettingFromDocumentCorrect()
        {
            using (var document = new DocxDocument(Resources.WithManyPlaceholders))
            {
                var placeholders = DocumentPlaceholder.Get(document.GetWordDocument(), "INNER");

                Assert.NotNull(placeholders);
                Assert.AreEqual(3, placeholders.Count());
            }
        }