BuildingBlockGallery
Contents
[
Hide
]BuildingBlockGallery enumeration
Specifies the predefined gallery into which a building block is classified.
public enum BuildingBlockGallery
Values
Name | Value | Description |
---|---|---|
All | 0 | Specifies that this glossary document entry shall be associated with all possible gallery classification values. |
AutoText | 1 | |
Bibliography | 2 | |
CoverPage | 3 | |
CustomAutoText | 4 | |
CustomBibliography | 5 | |
CustomCoverPage | 6 | |
CustomEquations | 7 | |
CustomFooters | 8 | |
CustomHeaders | 9 | |
Custom1 | 10 | |
Custom2 | 11 | |
Custom3 | 12 | |
Custom4 | 13 | |
Custom5 | 14 | |
CustomPageNumber | 15 | |
CustomPageNumberAtBottom | 16 | |
CustomPageNumberAtMargin | 17 | |
CustomPageNumberAtTop | 18 | |
CustomQuickParts | 19 | |
CustomTableOfContents | 20 | |
CustomTables | 21 | |
CustomTextBox | 22 | |
CustomWatermarks | 23 | |
NoGallery | 24 | |
QuickParts | 25 | |
Equations | 26 | |
Footers | 27 | |
Headers | 28 | |
PageNumber | 29 | |
PageNumberAtBottom | 30 | |
PageNumberAtMargin | 31 | |
PageNumberAtTop | 32 | |
StructuredDocumentTagPlaceholderText | 33 | |
TableOfContents | 34 | |
Tables | 35 | |
TextBox | 36 | |
Watermarks | 37 | |
Default | 0 | Same as All. |
Remarks
Corresponds to the ST_DocPartGallery type in OOXML.
Examples
Shows ways of accessing building blocks in a glossary document.
public void GlossaryDocument()
{
Document doc = new Document();
GlossaryDocument glossaryDoc = new GlossaryDocument();
BuildingBlock child1 = new BuildingBlock(glossaryDoc) { Name = "Block 1" };
glossaryDoc.AppendChild(child1);
BuildingBlock child2 = new BuildingBlock(glossaryDoc) { Name = "Block 2" };
glossaryDoc.AppendChild(child2);
BuildingBlock child3 = new BuildingBlock(glossaryDoc) { Name = "Block 3" };
glossaryDoc.AppendChild(child3);
BuildingBlock child4 = new BuildingBlock(glossaryDoc) { Name = "Block 4" };
glossaryDoc.AppendChild(child4);
BuildingBlock child5 = new BuildingBlock(glossaryDoc) { Name = "Block 5" };
glossaryDoc.AppendChild(child5);
Assert.AreEqual(5, glossaryDoc.BuildingBlocks.Count);
doc.GlossaryDocument = glossaryDoc;
// There are various ways of accessing building blocks.
// 1 - Get the first/last building blocks in the collection:
Assert.AreEqual("Block 1", glossaryDoc.FirstBuildingBlock.Name);
Assert.AreEqual("Block 5", glossaryDoc.LastBuildingBlock.Name);
// 2 - Get a building block by index:
Assert.AreEqual("Block 2", glossaryDoc.BuildingBlocks[1].Name);
Assert.AreEqual("Block 3", glossaryDoc.BuildingBlocks.ToArray()[2].Name);
// 3 - Get the first building block that matches a gallery, name and category:
Assert.AreEqual("Block 4",
glossaryDoc.GetBuildingBlock(BuildingBlockGallery.All, "(Empty Category)", "Block 4").Name);
// We will do that using a custom visitor,
// which will give every BuildingBlock in the GlossaryDocument a unique GUID
GlossaryDocVisitor visitor = new GlossaryDocVisitor();
// Visit start/end of the Glossary document.
glossaryDoc.Accept(visitor);
// Visit only start of the Glossary document.
glossaryDoc.AcceptStart(visitor);
// Visit only end of the Glossary document.
glossaryDoc.AcceptEnd(visitor);
Console.WriteLine(visitor.GetText());
// In Microsoft Word, we can access the building blocks via "Insert" -> "Quick Parts" -> "Building Blocks Organizer".
doc.Save(ArtifactsDir + "BuildingBlocks.GlossaryDocument.dotx");
}
/// <summary>
/// Gives each building block in a visited glossary document a unique GUID.
/// Stores the GUID-building block pairs in a dictionary.
/// </summary>
public class GlossaryDocVisitor : DocumentVisitor
{
public GlossaryDocVisitor()
{
mBlocksByGuid = new Dictionary<Guid, BuildingBlock>();
mBuilder = new StringBuilder();
}
public string GetText()
{
return mBuilder.ToString();
}
public Dictionary<Guid, BuildingBlock> GetDictionary()
{
return mBlocksByGuid;
}
public override VisitorAction VisitGlossaryDocumentStart(GlossaryDocument glossary)
{
mBuilder.AppendLine("Glossary document found!");
return VisitorAction.Continue;
}
public override VisitorAction VisitGlossaryDocumentEnd(GlossaryDocument glossary)
{
mBuilder.AppendLine("Reached end of glossary!");
mBuilder.AppendLine("BuildingBlocks found: " + mBlocksByGuid.Count);
return VisitorAction.Continue;
}
public override VisitorAction VisitBuildingBlockStart(BuildingBlock block)
{
block.Guid = Guid.NewGuid();
mBlocksByGuid.Add(block.Guid, block);
return VisitorAction.Continue;
}
public override VisitorAction VisitBuildingBlockEnd(BuildingBlock block)
{
mBuilder.AppendLine("\tVisited block \"" + block.Name + "\"");
mBuilder.AppendLine("\t Type: " + block.Type);
mBuilder.AppendLine("\t Gallery: " + block.Gallery);
mBuilder.AppendLine("\t Behavior: " + block.Behavior);
mBuilder.AppendLine("\t Description: " + block.Description);
return VisitorAction.Continue;
}
private readonly Dictionary<Guid, BuildingBlock> mBlocksByGuid;
private readonly StringBuilder mBuilder;
}
See Also
- namespace Aspose.Words.BuildingBlocks
- assembly Aspose.Words