I am trying to find the combo box selected value inside the table cell. I have been using the following code. But it is not working. Can you please help me with this: (Attached template)
Aspose.Words.Tables.Table tblEngagementDetails = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
foreach (StructuredDocumentTag sdt in tblEngagementDetails.GetChild(NodeType.StructuredDocumentTag, i, true))
{
if (sdt.SdtType == SdtType.ComboBox)
{
SdtListItem secondItem = sdt.ListItems[2];
sdt.ListItems.SelectedValue = secondItem;
}
}
Hi Joe,
The control used in your document is neither a content control nor a form field. It is a ActiveX control which is not supported by Aspose.Words at the moment. A new feature request to support ActiveX has already been logged into our issue tracking system as WORDSNET-1877. We will keep you updated on this issue in this thread.
Currently ActiveX controls can be read as a Shape. so you need to replace StructuredDocumentTag with a Shape in your code.
If you want to use content controls, you can use the following code.
var doc = new Document("Sample.docx");
foreach (StructuredDocumentTag sdt in doc.GetChildNodes(NodeType.StructuredDocumentTag, true, true))
{
if (sdt.SdtType == SdtType.DropDownList)
{
SdtListItem secondItem = sdt.ListItems[2];
sdt.ListItems.SelectedValue = secondItem;
Console.WriteLine(sdt.ListItems.SelectedValue.Value);
}
else if (sdt.SdtType == SdtType.ComboBox)
{
SdtListItem secondItem = sdt.ListItems[1];
sdt.ListItems.SelectedValue = secondItem;
Console.WriteLine(sdt.ListItems.SelectedValue.Value);
}
}
doc.Save("AsposeOut.Docx");