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

Free Support Forum - aspose.com

Convert plain text content control (STRUCTURED_DOCUMENT_TAG) to drop down content control (either combo box or drop down list)

Hi ,

I need to convert plain text content control (STRUCTURED_DOCUMENT_TAG) to drop down content control (either combo box or drop down list) in the word document. Can you please direct me to the code.

Thanks

@saurabh.arora,

Please ZIP and attach the following resources here for testing:

  • Your simplified input Word document containing the plain text content control
  • Your expected Word document showing the desired output. You can create expected document by using MS Word.

As soon as you get these pieces of information ready, we will start investigation into your scenario and provide you code to achieve the same by using Aspose.Words. Thanks for your cooperation.

Hi Awais,

Thanks for the reply. Please find the zip containing the input docx and output docx.
documents.zip (22.9 KB)

The input docx contains 3 plain text sdts and output docx contains 1 drop down list sdt , 1 combo box sdt and 1 plain text sdt.

I need to convert 2 plain text sdt to drop down and combo box sdt.

Thanks

@saurabh.arora,

We are checking this scenario on our end and will get back to you soon.

@saurabh.arora,

The following C# Code of Aspose.Words for .NET API demonstrates the standard way of adding Drop-Down List Content Control (StructuredDocumentTag) in Word document:

Document doc = new Document("E:\\Temp\\Documents\\input.docx");

StructuredDocumentTag sdt = new StructuredDocumentTag(doc, SdtType.DropDownList, MarkupLevel.Inline);

for (int i = 0; i < 5; i++)
    sdt.ListItems.Add(new SdtListItem("Display Text " + i, i.ToString()));

sdt.ListItems.SelectedValue = sdt.ListItems[0];

doc.LastSection.Body.LastParagraph.AppendChild(sdt);

doc.Save("E:\\Temp\\Documents\\20.3.docx");

However, for your case, you first need to read the value of Plain Text Content Control, then create a Drop-Down List (or Combo-Box) Content Control using that value, then insert Drop-Down List Content Control at the same place and finally remove the Plain Text Content Control. Please check following code for example:

Document doc = new Document("E:\\Temp\\Documents\\input.docx");

StructuredDocumentTag plainTextContentControl = null;
foreach (StructuredDocumentTag contentControl in doc.GetChildNodes(NodeType.StructuredDocumentTag, true))
{
    if (contentControl.Title.Equals("Agreement Type Ux 2.0 -- Rc 1.35"))
    {
        plainTextContentControl = contentControl;
        break;
    }
}

if (plainTextContentControl != null)
{
    StructuredDocumentTag dropDownListContentControl = new StructuredDocumentTag(doc, SdtType.DropDownList, MarkupLevel.Inline);
    dropDownListContentControl.ListItems.Add(new SdtListItem(plainTextContentControl.ToString(SaveFormat.Text), "0"));
    dropDownListContentControl.ListItems.SelectedValue = dropDownListContentControl.ListItems[0];

    plainTextContentControl.ParentNode.InsertBefore(dropDownListContentControl, plainTextContentControl);
    plainTextContentControl.Remove();
}

doc.Save("E:\\Temp\\Documents\\20.3.docx");

Hope, this helps.