SDT in SDT

Hi,

Please see the structure of the attached document using Document Explorer. Is there a way that I could recreate such a structure with your API? Apparently Word is allowing rich text content control to contain another rich text content control within itself.

Thanks,
Zeljko

Hi Zeljko,

Thanks for your inquiry. Yes, you can achieve your requirements using Aspose.Words. Please check following code example. Hope this helps you.

Document doc = new Document();
Table table = new Table(doc);
// Add the table to the document.
doc.getFirstSection().getBody().appendChild(table);
Row row = new Row(doc);
table.appendChild(row);
// We can now apply any auto fit settings.
table.autoFit(AutoFitBehavior.AUTO_FIT_TO_WINDOW);
StructuredDocumentTag sdtrow = new StructuredDocumentTag(doc, SdtType.RICH_TEXT, MarkupLevel.CELL);
sdtrow.removeAllChildren();
row.appendChild(sdtrow);
// Create a cell and add it to the row
Cell cell = new Cell(doc);
// Add a paragraph to the cell as well as a new run with some text.
cell.appendChild(new Paragraph(doc));
cell.getFirstParagraph().appendChild(new Run(doc, "Row 1, Cell 1 Text"));
// Add the cell to the StructuredDocumentTag.
sdtrow.appendChild(cell);
StructuredDocumentTag firstSdt = new StructuredDocumentTag(doc, SdtType.RICH_TEXT, MarkupLevel.BLOCK);
doc.getFirstSection().getBody().appendChild(firstSdt);
firstSdt.removeAllChildren();
firstSdt.setTitle("mainsdt");
StructuredDocumentTag secondSdt = new StructuredDocumentTag(doc, SdtType.RICH_TEXT, MarkupLevel.BLOCK);
firstSdt.appendChild(secondSdt);
secondSdt.removeAllChildren();
Paragraph paragraph = new Paragraph(doc);
paragraph.appendChild(new Run(doc, "Hello"));
secondSdt.appendChild(paragraph);
secondSdt.setTitle("secondSdt");
doc.save(MyDir + "Out.docx");