BuildingBlockGallery
内容
[
隐藏
]BuildingBlockGallery enumeration
指定构建块分类到的预定义库。
public enum BuildingBlockGallery
价值观
姓名 | 价值 | 描述 |
---|---|---|
All | 0 | 指定该词汇表文档条目应与所有可能的图库分类值相关联。 |
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 | 与相同All. |
评论
对应于ST_DocPartGallery输入 OOXML。
例子
显示访问术语表文档中的构建块的方法。
public void GlossaryDocument()
{
Document doc = new Document();
GlossaryDocument glossaryDoc = new GlossaryDocument();
glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc) { Name = "Block 1" });
glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc) { Name = "Block 2" });
glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc) { Name = "Block 3" });
glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc) { Name = "Block 4" });
glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc) { Name = "Block 5" });
Assert.AreEqual(5, glossaryDoc.BuildingBlocks.Count);
doc.GlossaryDocument = glossaryDoc;
// 访问构建块的方式有多种。
// 1 - 获取集合中的第一个/最后一个构建块:
Assert.AreEqual("Block 1", glossaryDoc.FirstBuildingBlock.Name);
Assert.AreEqual("Block 5", glossaryDoc.LastBuildingBlock.Name);
// 2 - 通过索引获取构建块:
Assert.AreEqual("Block 2", glossaryDoc.BuildingBlocks[1].Name);
Assert.AreEqual("Block 3", glossaryDoc.BuildingBlocks.ToArray()[2].Name);
// 3 - 获取与画廊、名称和类别匹配的第一个构建块:
Assert.AreEqual("Block 4",
glossaryDoc.GetBuildingBlock(BuildingBlockGallery.All, "(Empty Category)", "Block 4").Name);
// 我们将使用自定义访问者来做到这一点,
// 这将为 GlossaryDocument 中的每个 BuildingBlock 提供唯一的 GUID
GlossaryDocVisitor visitor = new GlossaryDocVisitor();
glossaryDoc.Accept(visitor);
Console.WriteLine(visitor.GetText());
// 在 Microsoft Word 中,我们可以通过“插入”-> 来访问构建块“快速零件”-> “积木组织者”。
doc.Save(ArtifactsDir + "BuildingBlocks.GlossaryDocument.dotx");
}
/// <summary>
/// 为访问的术语表文档中的每个构建块提供唯一的 GUID。
/// 将 GUID 构建块对存储在字典中。
/// </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;
}