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 eine Zitierung dar.
Equation3Der SDT stellt eine Gleichung dar.
DropDownList4Das SDT stellt eine Dropdown-Liste dar, wenn es im Dokument angezeigt wird.
ComboBox5Das SDT stellt ein Kombinationsfeld dar, wenn es im Dokument angezeigt wird.
Date6Das SDT stellt eine Datumsauswahl dar, wenn es im Dokument angezeigt wird.
BuildingBlockGallery7Das SDT stellt einen Baustein-Galerietyp dar.
DocPartObj8Das SDT stellt einen Dokumentteiltyp dar.
Group9Das SDT stellt eine eingeschränkte Gruppierung dar, wenn es im Dokument angezeigt wird.
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 ein einfaches Textfeld dar, wenn es im Dokument angezeigt wird.
Checkbox13Das SDT stellt ein Kontrollkästchen dar, wenn es im Dokument angezeigt wird.
RepeatingSection14Das SDT stellt den wiederkehrenden 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 man ein gruppenstrukturiertes Dokument-Tag auf Zeilenebene erstellt.

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

Table table = builder.StartTable();

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

// Eine untergeordnete Zeile des strukturierten Dokument-Tags erstellen.
Row row = new Row(doc);
groupSdt.AppendChild(row);

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

builder.EndTable();

// Zellinhalt 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);

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

// 2 – Einen Stil im Dokument namentlich referenzieren:
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();

// Erstelle 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);

// Wiederholendes Abschnittselement innerhalb des sich wiederholenden Abschnitts hinzufügen und als Zeile markieren.
// Diese Tabelle enthält eine Zeile für jedes Element, das wir im XML-Dokument finden können
// Verwenden des XPaths „/books[1]/book“, von dem 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 den erstellten Tabellenzellen für den Titel und den Autor jedes Buchs 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