/// <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(); }
/// <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(); }
public void PlaceholderGettingWhichNotExistsReturnsEmpty() { using (var document = new DocxDocument(Resources.WithMainContentTag)) { var placeholders = DocumentPlaceholder.Get(document.GetWordDocument(), "NON_EXISTING"); Assert.IsEmpty(placeholders); } }
public void TagGettingWhichNotExistsReturnsEmpty() { using (var document = new DocxDocument(Resources.WithMainContentTag)) { var tags = DocumentTag.Get(document.GetWordDocument(), "NON_EXISTING"); Assert.IsEmpty(tags); } }
public void TagGettingWhichNotExistsReturnsEmpty() { using (var document = new DocxDocument(Resources.WithMainContentTag)) { var tags = DocumentTag.Get(document.GetWordDocument(), "NON_EXISTING"); Assert.IsEmpty(tags); } }
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); } }
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()); } }
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()); } }
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()); } }
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); } }
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)); } }
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); } }
private static ICollection <Paragraph> GetParagraphs(DocxDocument document) { return(document.GetWordDocument().MainDocumentPart.Document.Descendants().OfType <Paragraph>().ToArray()); }