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

Free Support Forum - aspose.com

Dropdown list choose an item is not in SdtListItem

I have two dropdown list in word, both has an item with display name = “choose an item” and value = ‘’, as in attachment image,
but in code

ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream();
InputStream in;				
in = this.getClass().getResourceAsStream("/resources/dropdown1.docx");
Document doc = new Document(in);
NodeCollection sdtNodes = doc.getChildNodes(NodeType.STRUCTURED_DOCUMENT_TAG, true);
for (StructuredDocumentTag sdt : (Iterable<StructuredDocumentTag>)sdtNodes)
	 if (sdt.getSdtType() == SdtType.DROP_DOWN_LIST)
		for (SdtListItem item : (Iterable<SdtListItem>)sdt.getListItems()) {
			System.out.println(item.getDisplayText() + " | " + item.getValue());
		 }
doc.save(baOutputStream, SaveFormat.DOCX);
  1. only one dropdown list (dropdown1) has item.value = “| Choose an item.” (but not in item.getDisplayText()), another dropdown list (civilDept5_1) even has no item with value or displayText = “Choose an item”, why?
  2. when I save the document and download the document, I find only one dropdown list (dropdown1) has the “choose an item” choice, another dropdown list (civilDept5) has lost this choice, why?

dropdown_1.jpg (118.9 KB)
civitDept5_1.jpg (154.9 KB)
code1.jpg (138.3 KB)

@tong123123 Could you please attach your input and output documents here for testing? We will check the issue and provide you more information.

input as follow:
dropdown1.docx (21.0 KB)
output as follow:
dropdown1_ouput.docx (18.1 KB)

I found if the “choose an item” has value (dropdown2.docx, dropdown2_output.docx), then after download back the document, the “choose an item” will preserve, but don’t know why the first dropdown list can have empty value but after download back the document, the “choose an item” can still shown.

dropdown2.docx (21.0 KB)
dropdown2_ouput.docx (18.1 KB)

thanks.

@tong123123 Thank you for additional information. I have managed to reproduce the problem and logged it as WORDSNET-24793. We will keep you informed and let you know once it is resolved.
The difference between the dropdowns in your document is the following. In the first dropdown "Choose an item." items in the dropdown has value, but does not have displayed text:

<w:dropDownList>
	<w:listItem w:value="Choose an item."/>
	<w:listItem w:displayText="one" w:value="1"/>
	<w:listItem w:displayText="two" w:value="2"/>
</w:dropDownList>

In this case Aspose.Words preserves this item.
In the second dropdown, value of the "Choose an item." item is empty string and Aspose.Words skips this item:

<w:dropDownList>
	<w:listItem w:displayText="Choose an item." w:value=""/>
	<w:listItem w:displayText="Agriculture, Fisheries and Conservation Department" w:value="AFCD"/>
	<w:listItem w:displayText="Architectural Services Department" w:value="ARCHSD"/>

Dropdown controls also have placeholders, you can check sdt.isShowingPlaceholderText() and sdt.getPlaceholder() properties. For both dropdowns sdt.getPlaceholder().toString(SaveFormat.TEXT) returns "Choose an item.". This is the text you see when none of the items is selected.

1 Like

Anyway, under what situation will dropdown list has value, but does not have displayed text and under what situation will dropdown list has displayText but no value?

@tong123123 MS Word by default adds an "Choose an item." without display text. You can create in MS Word an item with Display Text but with empty Value. Like this:

<w:dropDownList>
	<w:listItem w:value="Choose an item."/> <!-- Created by default -->
	<w:listItem w:displayText="test" w:value=""/> <!-- Created manually with empty value -->
</w:dropDownList>
1 Like