StructuredDocumentTagPlaceholderName Property |
Gets or sets Name of the BuildingBlock containing placeholder text.
BuildingBlock with this name Name has to be present in the GlossaryDocument otherwise InvalidOperationException will occur.
Namespace: Aspose.Words.Markup
Document doc = new Document(); // Insert a plain text StructuredDocumentTag of the PlainText type, which will function like a text box // It contains a default "Click here to enter text." prompt, which we can click and replace with our own text StructuredDocumentTag tag = new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline); // We can substitute that default placeholder with a custom phrase, which will be drawn from a BuildingBlock // First we will need to create the BuildingBlock, give it content and add it to the GlossaryDocument GlossaryDocument glossaryDoc = doc.GlossaryDocument; BuildingBlock substituteBlock = new BuildingBlock(glossaryDoc); substituteBlock.Name = "Custom Placeholder"; substituteBlock.AppendChild(new Section(glossaryDoc)); substituteBlock.FirstSection.AppendChild(new Body(glossaryDoc)); substituteBlock.FirstSection.Body.AppendParagraph("Custom placeholder text."); glossaryDoc.AppendChild(substituteBlock); // The substitute BuildingBlock we made can be referenced by name tag.PlaceholderName = "Custom Placeholder"; // If PlaceholderName refers to an existing block in the parent document's GlossaryDocument, // the BuildingBlock will be automatically found and assigned to the Placeholder attribute Assert.AreEqual(substituteBlock, tag.Placeholder); // Setting this to true will register the text inside the StructuredDocumentTag as placeholder text // This means that, in Microsoft Word, all the text contents of the StructuredDocumentTag will be highlighted with one click, // so we can immediately replace the entire substitute text by typing // If this is false, the text will behave like an ordinary Paragraph and a cursor will be placed with nothing highlighted tag.IsShowingPlaceholderText = true; // Insert the StructuredDocumentTag into the document using a DocumentBuilder and save the document to a file DocumentBuilder builder = new DocumentBuilder(doc); builder.InsertNode(tag); doc.Save(ArtifactsDir + "StructuredDocumentTag.PlaceholderBuildingBlock.docx");