Insert Structured Document Tag

Record.docx (16.6 KB)

I want to insert a row for “college” in between rows of “school” & “college” as shown in attached document. I am using 20.12 version of aspose.words but I am unable to do it through builder. It says “cannot insert at required location”

@muniryousafzai Actually each record in your document is represented as a separate table:

So you can simply clone the first table and insert the cloned table after it. For example see the following code:

Document doc = new Document("C:\\Temp\\in.docx");

// Get the first table.
Table table = (Table)doc.getFirstSection().getBody().getTables().get(0);

// Clone the table
Table clone = (Table)table.deepClone(true);

// Insert an empty paragraph after the original table.
table.getParentNode().insertAfter(new Paragraph(doc), table);

// Insert the cloned table after the empty paragraph.
table.getParentNode().insertAfter(clone, table.getNextSibling());

// Change tags in SDTs.
StructuredDocumentTag sdt1 = (StructuredDocumentTag)clone.getRange().getStructuredDocumentTags().getByTag("School");
StructuredDocumentTag sdt2 = (StructuredDocumentTag)clone.getRange().getStructuredDocumentTags().getByTag("SchoolName");
sdt1.setTag("College");
sdt2.setTag("CollegeName");

doc.save("C:\\Temp\\out.docx");