We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Changing the Level of a StructuredDocumentTag in Aspose.Words

Changing the Level of a StructuredDocumentTag in Aspose.Words

I am developing an application, which generates business-mail by filling StructuredDocumentTags using Aspose.Words in existing Word-Document
I would like to know, if there is any way to change the “Level” of a StructuredDocumentTag in an open Aspose.Words.Document from “Inline” to “Block” using Aspose.Words. The class-member “Level” in the class “StructuredDocumentTag” is read-only. Is there perhaps a solution using the “DocumentBuilder”?
Is there is any solution for that, this would save us much work editing >100 .dotx files.

Thanks!

@tgjas There is no way to change level of SDT and this is not something that you can easily do. Inline SDT can be placed only as inline node, like Run, so you can have several inline SDT in the same paragraph. On other hand block level SDT can be placed on the same level as a paragraph.
You can try inserting block level SDT at the position of inline and then remove inline, but this might lean into document layout change:

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

foreach (StructuredDocumentTag sdt in doc.Range.StructuredDocumentTags)
{
    if (sdt.Level == MarkupLevel.Inline)
    {
        StructuredDocumentTag blockSdt = new StructuredDocumentTag(doc, sdt.SdtType, MarkupLevel.Block);

        // get parent paragraph and insert block level SDT after it.
        Paragraph parentPara = (Paragraph)sdt.GetAncestor(NodeType.Paragraph);

        parentPara.ParentNode.InsertAfter(blockSdt, parentPara);

        sdt.Remove();
    }
}

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