Esempio n. 1
0
        /// <summary>
        /// Create builder for template
        /// </summary>
        /// <param name="docxDocument">Template document</param>
        /// <param name="tagVisibilityOptions">List of tags for show and hide</param>
        public DocxDocumentBuilder(DocxDocument docxDocument, TagVisibilityOptions tagVisibilityOptions = null)
            : base(docxDocument.GetWordDocument())
        {
            this.docxDocument         = docxDocument;
            this.tagVisibilityOptions = tagVisibilityOptions;

            MergeVanishedRuns();
        }
Esempio n. 2
0
        /// <summary>
        /// Create builder for template
        /// </summary>
        /// <param name="docxDocument">Template document</param>
        /// <param name="tagVisibilityOptions">List of tags for show and hide</param>
        public DocxDocumentBuilder(DocxDocument docxDocument, TagVisibilityOptions tagVisibilityOptions = null)
            : base(docxDocument.GetWordDocument())
        {
            this.docxDocument = docxDocument;
            this.tagVisibilityOptions = tagVisibilityOptions;

            MergeVanishedRuns();
        }
Esempio n. 3
0
        public void PlaceholderGettingWhichNotExistsReturnsEmpty()
        {
            using (var document = new DocxDocument(Resources.WithMainContentTag))
            {
                var placeholders = DocumentPlaceholder.Get(document.GetWordDocument(), "NON_EXISTING");

                Assert.IsEmpty(placeholders);
            }
        }
Esempio n. 4
0
        public void TagGettingWhichNotExistsReturnsEmpty()
        {
            using (var document = new DocxDocument(Resources.WithMainContentTag))
            {
                var tags = DocumentTag.Get(document.GetWordDocument(), "NON_EXISTING");

                Assert.IsEmpty(tags);
            }
        }
Esempio n. 5
0
        public void TagGettingWhichNotExistsReturnsEmpty()
        {
            using (var document = new DocxDocument(Resources.WithMainContentTag))
            {
                var tags = DocumentTag.Get(document.GetWordDocument(), "NON_EXISTING");

                Assert.IsEmpty(tags);
            }
        }
Esempio n. 6
0
        public void ProtectAddWrightProtectionToFile()
        {
            using (var @protected = new DocxDocument(Resources.Protected))
                using (var @unprotected = new DocxDocument(Resources.Unprotected))
                {
                    @unprotected.Protect();

                    Assert.AreEqual(@protected.GetWordDocument().MainDocumentPart.DocumentSettingsPart.Settings.OuterXml, @unprotected.GetWordDocument().MainDocumentPart.DocumentSettingsPart.Settings.OuterXml);
                }
        }
Esempio n. 7
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());
            }
        }
Esempio n. 8
0
        public void ManyTagsGettingFromDocumentCorrect()
        {
            using (var document = new DocxDocument(Resources.WithManyTags))
            {
                var tags = DocumentTag.Get(document.GetWordDocument(), "SUB");

                Assert.NotNull(tags);
                Assert.AreEqual(3, tags.Count());
            }
        }
Esempio n. 9
0
        public void ManyTagsGettingFromDocumentCorrect()
        {
            using (var document = new DocxDocument(Resources.WithManyTags))
            {
                var tags = DocumentTag.Get(document.GetWordDocument(), "SUB");

                Assert.NotNull(tags);
                Assert.AreEqual(3, tags.Count());
            }
        }
Esempio n. 10
0
        public void SetCustomPropertyToDocument()
        {
            using (var withoutAttributes = new DocxDocument(Resources.DocumentWithoutAttributes))
                using (var withAttribute = new DocxDocument(Resources.DocumentWithAttribute))
                {
                    withoutAttributes.SetCustomProperty("customAttributes", "Working");

                    var withoutAttributesOuterXml = withoutAttributes.GetWordDocument().CustomFilePropertiesPart.Properties.Single(x => x.LocalName == "property").OuterXml;
                    var withAttributeOuterXml     = withAttribute.GetWordDocument().CustomFilePropertiesPart.Properties.Single(x => x.LocalName == "property").OuterXml;

                    Assert.AreEqual(withAttributeOuterXml, withoutAttributesOuterXml);
                }
        }
Esempio n. 11
0
        public void UnprotectRemovesWrightProtectionFromFile()
        {
            using (var @protected = new DocxDocument(Resources.Protected))
                using (var @unprotected = new DocxDocument(Resources.Unprotected))
                {
                    @protected.Unprotect();

                    var unprotectedOuterXml = @unprotected.GetWordDocument().MainDocumentPart.DocumentSettingsPart.Settings.OuterXml;
                    var protectedOuterXml   = @protected.GetWordDocument().MainDocumentPart.DocumentSettingsPart.Settings.OuterXml;

                    Assert.IsTrue(unprotectedOuterXml.Equals(protectedOuterXml, StringComparison.InvariantCultureIgnoreCase));
                }
        }
Esempio n. 12
0
        public void SetCustomPropertyToDocumentIfItAlreadyHasProperties()
        {
            using (var withTwoAttributes = new DocxDocument(Resources.DocumentWithTwoAttributes))
                using (var withAttribute = new DocxDocument(Resources.DocumentWithAttribute))
                {
                    withAttribute.SetCustomProperty("customAttributes2", "Working2");

                    var propertiesWithTwoAttributes = withTwoAttributes.GetWordDocument().CustomFilePropertiesPart.Properties;
                    var propertiesWithAttribute     = withAttribute.GetWordDocument().CustomFilePropertiesPart.Properties;

                    Assert.AreEqual(propertiesWithTwoAttributes.First(x => x.LocalName == "property").OuterXml,
                                    propertiesWithAttribute.First(x => x.LocalName == "property").OuterXml);
                    Assert.AreEqual(propertiesWithTwoAttributes.Last(x => x.LocalName == "property").OuterXml,
                                    propertiesWithAttribute.Last(x => x.LocalName == "property").OuterXml);
                }
        }
Esempio n. 13
0
 private static ICollection <Paragraph> GetParagraphs(DocxDocument document)
 {
     return(document.GetWordDocument().MainDocumentPart.Document.Descendants().OfType <Paragraph>().ToArray());
 }