public class SdtType
Example: Example:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Get specific style from the document to apply it to an SDT
Style quoteStyle = doc.getStyles().getByStyleIdentifier(StyleIdentifier.QUOTE);
StructuredDocumentTag sdtPlainText = new StructuredDocumentTag(doc, SdtType.PLAIN_TEXT, MarkupLevel.INLINE);
sdtPlainText.setStyle(quoteStyle);
StructuredDocumentTag sdtRichText = new StructuredDocumentTag(doc, SdtType.RICH_TEXT, MarkupLevel.INLINE);
// Second method to apply specific style to an SDT control
sdtRichText.setStyleName("Quote");
// Insert content controls into the document
builder.insertNode(sdtPlainText);
builder.insertNode(sdtRichText);
// We can get a collection of StructuredDocumentTags by looking for the document's child nodes of this NodeType
Assert.assertEquals(sdtPlainText.getNodeType(), NodeType.STRUCTURED_DOCUMENT_TAG);
NodeCollection tags = doc.getChildNodes(NodeType.STRUCTURED_DOCUMENT_TAG, true);
for (StructuredDocumentTag sdt : (Iterable<StructuredDocumentTag>) tags) {
// If style was not defined before, style should be "Default Paragraph Font"
Assert.assertEquals(StyleIdentifier.QUOTE, sdt.getStyle().getStyleIdentifier());
Assert.assertEquals("Quote", sdt.getStyleName());
}
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
CustomXmlPart xmlPart = doc.getCustomXmlParts().add("Books",
"<books>" +
"<book><title>Everyday Italian</title>" +
"<author>Giada De Laurentiis</author></book>" +
"<book><title>Harry Potter</title>" +
"<author>J K. Rowling</author></book>" +
"<book><title>Learning XML</title>" +
"<author>Erik T. Ray</author></book>" +
"</books>");
// Create headers for data from xml content
Table table = builder.startTable();
builder.insertCell();
builder.write("Title");
builder.insertCell();
builder.write("Author");
builder.endRow();
builder.endTable();
// Create table with RepeatingSection inside
StructuredDocumentTag repeatingSectionSdt =
new StructuredDocumentTag(doc, SdtType.REPEATING_SECTION, MarkupLevel.ROW);
repeatingSectionSdt.getXmlMapping().setMapping(xmlPart, "/books[1]/book", "");
table.appendChild(repeatingSectionSdt);
// Add RepeatingSectionItem inside RepeatingSection and mark it as a row
StructuredDocumentTag repeatingSectionItemSdt =
new StructuredDocumentTag(doc, SdtType.REPEATING_SECTION_ITEM, MarkupLevel.ROW);
repeatingSectionSdt.appendChild(repeatingSectionItemSdt);
Row row = new Row(doc);
repeatingSectionItemSdt.appendChild(row);
// Map xml data with created table cells for book title and author
StructuredDocumentTag titleSdt =
new StructuredDocumentTag(doc, SdtType.PLAIN_TEXT, MarkupLevel.CELL);
titleSdt.getXmlMapping().setMapping(xmlPart, "/books[1]/book[1]/title[1]", "");
row.appendChild(titleSdt);
StructuredDocumentTag authorSdt =
new StructuredDocumentTag(doc, SdtType.PLAIN_TEXT, MarkupLevel.CELL);
authorSdt.getXmlMapping().setMapping(xmlPart, "/books[1]/book[1]/author[1]", "");
row.appendChild(authorSdt);
doc.save(getArtifactsDir() + "StructuredDocumentTag.RepeatingSectionItem.docx");
Field Summary | ||
---|---|---|
static final int | NONE | |
No type is assigned to the SDT.
|
||
static final int | BIBLIOGRAPHY | |
The SDT represents a bibliography entry.
|
||
static final int | CITATION | |
The SDT represents a citation.
|
||
static final int | EQUATION | |
The SDT represents an equation.
|
||
static final int | DROP_DOWN_LIST | |
The SDT represents a drop down list when displayed in the document.
|
||
static final int | COMBO_BOX | |
The SDT represents a combo box when displayed in the document.
|
||
static final int | DATE | |
The SDT represents a date picker when displayed in the document.
|
||
static final int | BUILDING_BLOCK_GALLERY | |
The SDT represents a building block gallery type.
|
||
static final int | DOC_PART_OBJ | |
The SDT represents a document part type.
|
||
static final int | GROUP | |
The SDT represents a restricted grouping when displayed in the document.
|
||
static final int | PICTURE | |
The SDT represents a picture when displayed in the document.
|
||
static final int | RICH_TEXT | |
The SDT represents a rich text box when displayed in the document.
|
||
static final int | PLAIN_TEXT | |
The SDT represents a plain text box when displayed in the document.
|
||
static final int | CHECKBOX | |
The SDT represents a checkbox when displayed in the document.
|
||
static final int | REPEATING_SECTION | |
The SDT represents repeating section type when displayed in the document.
|
||
static final int | REPEATING_SECTION_ITEM | |
The SDT represents repeating section item.
|
||
static final int | ENTITY_PICKER | |
The SDT represents an entity picker that allows the user to select an instance of an external content type.
|
public static final int NONE
public static final int BIBLIOGRAPHY
public static final int CITATION
public static final int EQUATION
public static final int DROP_DOWN_LIST
public static final int COMBO_BOX
public static final int DATE
public static final int BUILDING_BLOCK_GALLERY
public static final int DOC_PART_OBJ
public static final int GROUP
public static final int PICTURE
public static final int RICH_TEXT
public static final int PLAIN_TEXT
public static final int CHECKBOX
public static final int REPEATING_SECTION
public static final int REPEATING_SECTION_ITEM
public static final int ENTITY_PICKER