SdtType

SdtType enumeration

Gibt den Typ eines SDT-Knotens (Structured Document Tag) an.

public enum SdtType

Werte

NameWertBeschreibung
None0Dem SDT ist kein Typ zugewiesen.
Bibliography1Das SDT stellt einen Bibliographieeintrag dar.
Citation2Das SDT stellt ein Zitat dar.
Equation3Das SDT stellt eine Gleichung dar.
DropDownList4Das SDT stellt eine Dropdown-Liste dar, wenn es im Dokument angezeigt wird.
ComboBox5Das SDT stellt bei Anzeige im Dokument ein Kombinationsfeld dar.
Date6Das SDT stellt eine Datumsauswahl dar, wenn es im Dokument angezeigt wird.
BuildingBlockGallery7Das SDT stellt einen Bausteingalerietyp dar.
DocPartObj8Das SDT stellt einen Dokumentteiltyp dar.
Group9Das SDT stellt bei der Anzeige im Dokument eine eingeschränkte Gruppierung dar.
Picture10Das SDT stellt ein Bild dar, wenn es im Dokument angezeigt wird.
RichText11Das SDT stellt ein Rich-Text-Feld dar, wenn es im Dokument angezeigt wird.
PlainText12Das SDT stellt bei der Anzeige im Dokument ein einfaches Textfeld dar.
Checkbox13Das SDT stellt ein Kontrollkästchen dar, wenn es im Dokument angezeigt wird.
RepeatingSection14Das SDT stellt den sich wiederholenden Abschnittstyp dar, wenn es im Dokument angezeigt wird.
RepeatingSectionItem15Das SDT stellt ein sich wiederholendes Abschnittselement dar.
EntityPicker16Das SDT stellt einen Entitätswähler dar, der es dem Benutzer ermöglicht, eine Instanz eines externen Inhaltstyps auszuwählen.

Beispiele

Zeigt, wie ein strukturiertes Dokument-Tag vom Typ „Zitat“ erstellt wird.

Document doc = new Document();

StructuredDocumentTag sdt = new StructuredDocumentTag(doc, SdtType.Citation, MarkupLevel.Inline);
Paragraph paragraph = doc.FirstSection.Body.FirstParagraph;
paragraph.AppendChild(sdt);

// Erstellen Sie ein Zitatfeld.
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToParagraph(0, -1);
builder.InsertField(@"CITATION Ath22 \l 1033 ", "(John Lennon, 2022)");

// Verschieben Sie das Feld in das strukturierte Dokument-Tag.
while (sdt.NextSibling != null)
    sdt.AppendChild(sdt.NextSibling);

doc.Save(ArtifactsDir + "StructuredDocumentTag.Citation.docx");

Zeigt, wie gruppenstrukturierte Dokument-Tags auf Zeilenebene erstellt werden.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Table table = builder.StartTable();

// Erstellen Sie auf Zeilenebene ein gruppenstrukturiertes Dokument-Tag.
StructuredDocumentTag groupSdt = new StructuredDocumentTag(doc, SdtType.Group, MarkupLevel.Row);
table.AppendChild(groupSdt);
groupSdt.IsShowingPlaceholderText = false;
groupSdt.RemoveAllChildren();

// Erstellen Sie eine untergeordnete Zeile des strukturierten Dokument-Tags.
Row row = new Row(doc);
groupSdt.AppendChild(row);

Cell cell = new Cell(doc);
row.AppendChild(cell);

builder.EndTable();

// Zelleninhalt einfügen.
cell.EnsureMinimum();
builder.MoveTo(cell.LastParagraph);
builder.Write("Lorem ipsum dolor.");

// Text nach der Tabelle einfügen.
builder.MoveTo(table.NextSibling);
builder.Write("Nulla blandit nisi.");

doc.Save(ArtifactsDir + "StructuredDocumentTag.SdtAtRowLevel.docx");

Zeigt, wie mit Stilen für Inhaltssteuerelemente gearbeitet wird.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Unten finden Sie zwei Möglichkeiten, einen Stil aus dem Dokument auf ein strukturiertes Dokument-Tag anzuwenden.
// 1 – Wenden Sie ein Stilobjekt aus der Stilsammlung des Dokuments an:
Style quoteStyle = doc.Styles[StyleIdentifier.Quote];
StructuredDocumentTag sdtPlainText =
    new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline) { Style = quoteStyle };

// 2 - Verweisen Sie im Dokument anhand des Namens auf einen Stil:
StructuredDocumentTag sdtRichText =
    new StructuredDocumentTag(doc, SdtType.RichText, MarkupLevel.Inline) { StyleName = "Quote" };

builder.InsertNode(sdtPlainText);
builder.InsertNode(sdtRichText);

Assert.AreEqual(NodeType.StructuredDocumentTag, sdtPlainText.NodeType);

NodeCollection tags = doc.GetChildNodes(NodeType.StructuredDocumentTag, true);

foreach (Node node in tags)
{
    StructuredDocumentTag sdt = (StructuredDocumentTag)node;

    Console.WriteLine(sdt.WordOpenXMLMinimal);

    Assert.AreEqual(StyleIdentifier.Quote, sdt.Style.StyleIdentifier);
    Assert.AreEqual("Quote", sdt.StyleName);
}

Zeigt, wie eine Tabelle mit Daten aus einem XML-Teil gefüllt wird.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

CustomXmlPart xmlPart = doc.CustomXmlParts.Add("Books",
    "<books>" +
        "<book>" +
            "<title>Everyday Italian</title>" +
            "<author>Giada De Laurentiis</author>" +
        "</book>" +
        "<book>" +
            "<title>The C Programming Language</title>" +
            "<author>Brian W. Kernighan, Dennis M. Ritchie</author>" +
        "</book>" +
        "<book>" +
            "<title>Learning XML</title>" +
            "<author>Erik T. Ray</author>" +
        "</book>" +
    "</books>");

// Header für Daten aus dem XML-Inhalt erstellen.
Table table = builder.StartTable();
builder.InsertCell();
builder.Write("Title");
builder.InsertCell();
builder.Write("Author");
builder.EndRow();
builder.EndTable();

// Erstellen Sie eine Tabelle mit einem sich wiederholenden Abschnitt darin.
StructuredDocumentTag repeatingSectionSdt =
    new StructuredDocumentTag(doc, SdtType.RepeatingSection, MarkupLevel.Row);
repeatingSectionSdt.XmlMapping.SetMapping(xmlPart, "/books[1]/book", string.Empty);
table.AppendChild(repeatingSectionSdt);

// Fügen Sie innerhalb des sich wiederholenden Abschnitts ein sich wiederholendes Abschnittselement hinzu und markieren Sie es als Zeile.
// Diese Tabelle enthält eine Zeile für jedes Element, das wir im XML-Dokument finden können
// unter Verwendung des XPath "/books[1]/book", von denen es drei gibt.
StructuredDocumentTag repeatingSectionItemSdt =
    new StructuredDocumentTag(doc, SdtType.RepeatingSectionItem, MarkupLevel.Row);
repeatingSectionSdt.AppendChild(repeatingSectionItemSdt);

Row row = new Row(doc);
repeatingSectionItemSdt.AppendChild(row);

// Ordnen Sie XML-Daten mit erstellten Tabellenzellen für den Titel und den Autor jedes Buches zu.
StructuredDocumentTag titleSdt =
    new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Cell);
titleSdt.XmlMapping.SetMapping(xmlPart, "/books[1]/book[1]/title[1]", string.Empty);
row.AppendChild(titleSdt);

StructuredDocumentTag authorSdt =
    new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Cell);
authorSdt.XmlMapping.SetMapping(xmlPart, "/books[1]/book[1]/author[1]", string.Empty);
row.AppendChild(authorSdt);

doc.Save(ArtifactsDir + "StructuredDocumentTag.RepeatingSectionItem.docx");

Siehe auch