ContentControl
APIs for the ContentControl object in Word documents.
ContentControls
ActiveDocument.ContentControls
Returns a collection of all content controls in the document.
This feature is supported in JS-SDK V1.1.10 and later.
-
Syntax
expression.ActiveDocument.ContentControlsexpression: An Application object.
-
Example
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const ContentControls = await app.ActiveDocument.ContentControls; }
Methods
ActiveDocument.ContentControls.Add()
Inserts a content control at the cursor.
This feature is supported in JS-SDK V1.1.11 and later.
-
Syntax
expression.ActiveDocument.ContentControls.Add({ Type })expression: An Application object.
-
Parameters
Property
Data type
Required
Description
Type
Enum
Yes
The type of the content control. This can be one of the WdContentControlType constants. If omitted, an RTF (rich text format) content control is inserted by default.
ImportantJS-SDK V1.1.15 and later support adding drop-down list content controls.
-
Return value
Returns the new content control object.
-
Examples
-
Add an RTF content control
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const contentControls = await app.ActiveDocument.ContentControls; // Insert an RTF content control at the cursor. await contentControls.Add(); } -
Add a drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const contentControls = await app.ActiveDocument.ContentControls; // Insert a drop-down list content control at the cursor. await contentControls.Add({ Type: 4, }); }
-
ActiveDocument.ContentControls.Item()
Retrieves a specified content control from the collection.
This feature is supported in JS-SDK V1.1.11 and later.
-
Syntax
expression.ActiveDocument.ContentControls.Item(Index)expression: An Application object.
-
Parameters
Property
Data type
Required
Description
Index
Number
Yes
The index of the content control to retrieve.
-
Return value
Returns a ContentControl object.
-
ExampleActiveDocument.ContentControls.SetItemsContent()
async function example() { await instance.ready(); const app = instance.Application; // Return the first ContentControl object. const contentControl = await app.ActiveDocument.ContentControls.Item(1); }Sets the content for multiple content controls in a batch. To use this method, you must set
wps.enableSuperContentControlApi = truein thejsconfigconfiguration file. -
Syntax
expression.ActiveDocument.ContentControls.SetItemsContent({ Value, Key, CompareTitle })expression: An Application object.
-
Parameters
Property
Data type
Required
Description
Value
String
Yes
The content to set.
Key
String
Yes
The Title or Tag keyword.
CompareTitle
Boolean
Yes
Whether to perform batch setting by title. If
true, batch setting is performed by Title. Iffalse, batch setting is performed by Tag. -
Example
async function example() { await instance.ready(); const app = instance.Application; const contentControls = await app.ActiveDocument.ContentControls; await contentControls.SetItemsContent({ Value: "Batch replace content of content controls", Key: "test", CompareTitle: true }); }
Properties
ActiveDocument.ContentControls.Count
Returns the number of content controls in the document.
-
Syntax
expression.ActiveDocument.ContentControls.Countexpression: An Application object.
-
Return value
A
Numberrepresenting the number of content controls in the document. -
Example
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const contentControls = await app.ActiveDocument.ContentControls; // Get the number of content controls. const count = await contentControls.Count; console.log(count); }
ContentControl
ActiveDocument.ContentControls.Item(Index)
Retrieves a single content control object.
This feature is supported in JS-SDK V1.1.10 and later.
-
Syntax
expression.ActiveDocument.ContentControls.Item(Index)expression: An Application object.
-
Parameters
Property
Data type
Required
Description
Index
String
Yes
The index of the content control to retrieve.
-
Return value
Returns the specified content control.
-
Example
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const contentControls = await app.ActiveDocument.ContentControls; // Get the first content control object. const contentControl = await contentControls.Item(1); }
ActiveDocument.ContentControls.Item(Index).SetPlaceholderText()
Sets the placeholder text for a content control.
-
Syntax
expression.ActiveDocument.ContentControls.Item(Index).SetPlaceholderText({ Text })expression: An Application object.
-
Parameters
Property
Data type
Required
Description
Text
String
Yes
The placeholder text to set for the content control.
-
Example
//@file=base.docx async function example() { await instance.ready(); const app = instance.Application; // The content control object. const contentControls = await app.ActiveDocument.ContentControls; // Get the first content control. const contentControl = await contentControls.Item(1); // Set the placeholder text for the first content control. await contentControl.SetPlaceholderText({ Text: 'WebOffice' }); }
Properties
ActiveDocument.ContentControls.Item(Index).PlaceholderText
Returns the placeholder text of a content control.
This feature is supported in JS-SDK V1.1.10 and later.
-
Syntax
expression.ActiveDocument.ContentControls.Item(Index).PlaceholderTextexpression: An Application object.
-
Example
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const contentControls = await app.ActiveDocument.ContentControls; // Get the first content control object. const contentControl = await contentControls.Item(1); // Get the placeholder text of this content control. const placeholderText = await contentControl.PlaceholderText; console.log(placeholderText); }
ActiveDocument.ContentControls.Item(Index).Range
Returns the range of a content control. Use Range.Text to get or set the text value of the content control.
This feature is supported in JS-SDK V1.1.12 and later.
-
Syntax
expression.ActiveDocument.ContentControls.Item(Index).Rangeexpression: An Application object.
-
Examples
-
Get the range of a content control
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const contentControls = await app.ActiveDocument.ContentControls; // Get the first content control object. const contentControl = await contentControls.Item(1); // Get the range of the content control. const range = await contentControl.Range; console.log(range); } -
Get and set the text value of a content control
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const contentControls = await app.ActiveDocument.ContentControls; // Get the first content control object. const contentControl = await contentControls.Item(1); // Get the range of the content control. const range = await contentControl.Range; // Get the text of the content control. const text = range.Text; console.log(text); // Set the text value of the content control. range.Text = 'Aliyun'; }
-
ActiveDocument.ContentControls.Item(Index).Tag
Gets or sets the tag of a content control.
This feature is supported in JS-SDK V1.1.10 and later.
-
Syntax
expression.ActiveDocument.ContentControls.Item(Index).Tagexpression: An Application object.
-
Example
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const contentControls = await app.ActiveDocument.ContentControls; // Get the first content control object. const contentControl = await contentControls.Item(1); // Set the tag for the content control. contentControl.Tag = 'Aliyun'; // Get the tag of the content control. const Tag = await contentControl.Tag; console.log(Tag); }
ActiveDocument.ContentControls.Item(Index).Title
Gets or sets the title of a content control.
This feature is supported in JS-SDK V1.1.10 and later.
-
Syntax
expression.ActiveDocument.ContentControls.Item(Index).Titleexpression: An Application object.
-
Example
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const contentControls = await app.ActiveDocument.ContentControls; // Get the first content control object. const contentControl = await contentControls.Item(1); // Set the title for the content control. contentControl.Title = 'Aliyun'; // Get the title of the content control. const title = await contentControl.Title; console.log(title); }
ContentControlListEntries
ActiveDocument.ContentControls.Item(Index).DropdownListEntries
Returns all list options in a drop-down list content control. This property is read-only.
This feature is supported in JS-SDK V1.1.15 and later.
-
Syntax
expression.ActiveDocument.ContentControls.Item(Index).DropdownListEntriesexpression: An Application object.
-
Examples
-
Get all options from a new drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const ContentControls = await app.ActiveDocument.ContentControls; // Add a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Get all list options of this drop-down list content control. const ContentControlListEntries = await ContentControl. DropdownListEntries; } -
Get all options from a drop-down list content control by index
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const ContentControls = await app.ActiveDocument.ContentControls; // Add a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Get the number of content controls in the document, including text and drop-down list content controls. // Assume there are 2 content controls (the console prints 2). The newly added content control is the second one. const Count = await WPSOpenApi.Application.ActiveDocument.ContentControls.Count; // Get all list options of this drop-down list content control. const ContentControlListEntries = await WPSOpenApi.Application.ActiveDocument.ContentControls.Item(Count).DropdownListEntries; }
-
Methods
ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Add()
Adds a new list option to a drop-down list or combo box content control. Returns a ContentControlListEntry object representing the new option.
This feature is supported in JS-SDK V1.1.15 and later.
-
Syntax
expression.ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Add({ Text, Value, Index })expression: An Application object.
-
Examples
-
Add options to a new drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const ContentControls = await app.ActiveDocument.ContentControls; // Add a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Get all list options of this drop-down list content control. const ContentControlListEntries = await ContentControl. DropdownListEntries; // Add a list option to this drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // Add a list option to this drop-down list content control. If you do not specify Value and Index, Value is the same as Text. await ContentControlListEntries.Add({ Text: 'Text 2', }); } -
Add a list option to a drop-down list content control by index
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const ContentControls = await app.ActiveDocument.ContentControls; // Add a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Get the number of content controls in the document, including text and drop-down list content controls. // Assume there are 2 content controls (the console prints 2). The newly added content control is the second one. const Count = await WPSOpenApi.Application.ActiveDocument.ContentControls.Count; // Get all list options of this drop-down list content control. const ContentControlListEntries = await WPSOpenApi.Application.ActiveDocument.ContentControls.Item(Count).DropdownListEntries; // Add a list option to this drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); }
-
ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Clear()
Clears all list options from a drop-down list or combo box content control.
This feature is supported in JS-SDK V1.1.15 and later.
-
Syntax
expression.ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Clear()expression: An Application object.
-
Examples
-
Clear all options from a new drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const ContentControls = await app.ActiveDocument.ContentControls; // Add a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Get all list options of this drop-down list content control. const ContentControlListEntries = await ContentControl. DropdownListEntries; // Add a list option to this drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // Add a list option to this drop-down list content control. If you do not specify Value and Index, Value is the same as Text. await ContentControlListEntries.Add({ Text: 'Text 2', }); // Clear all list options of this drop-down list content control after 3000 ms. setTimeout(async () => { await ContentControlListEntries.Clear(); }, 3000); } -
Clear all options from a drop-down list content control by index
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const ContentControls = await app.ActiveDocument.ContentControls; // Add a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Get the number of content controls in the document, including text and drop-down list content controls. // Assume there are 2 content controls (the console prints 2). The newly added content control is the second one. const Count = await WPSOpenApi.Application.ActiveDocument.ContentControls.Count; // Get all list options of this drop-down list content control. const ContentControlListEntries = await WPSOpenApi.Application.ActiveDocument.ContentControls.Item(Count).DropdownListEntries; // Add a list option to this drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // Clear all list options of this drop-down list content control after 3000 ms. setTimeout(async () => { await ContentControlListEntries.Clear(); }, 3000); }
-
ActiveDocument.ContentControls.Item(Index).DropdownListEntries.GetSelectedItem()
Returns information about the selected list option in a drop-down list content control.
This feature is supported in JS-SDK V1.1.15 and later.
-
Syntax
expression.ActiveDocument.ContentControls.Item(Index).DropdownListEntries.GetSelectedItem()expression: An Application object.
-
Examples
-
Get the selected option from a new drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const ContentControls = await app.ActiveDocument.ContentControls; // Add a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Get all list options of this drop-down list content control. const ContentControlListEntries = await ContentControl. DropdownListEntries; // Add a list option to this drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // Add a list option to this drop-down list content control. If you do not specify Value and Index, Value is the same as Text. await ContentControlListEntries.Add({ Text: 'Text 2', }); // Select the first list option of this drop-down list content control. await ContentControlListEntries.Item(1).Select(); // Get the information of this list option. const SelectedItem = await DropdownListEntries.GetSelectedItem(); console.log(SelectedItem); } -
Get the selected option from a drop-down list content control by index
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const ContentControls = await app.ActiveDocument.ContentControls; // Add a drop-down list content control. const ContentControl = await WPSOpenApi.Application.ActiveDocument.ContentControls.Add({ Type: 4, }); // Get the number of content controls in the document, including text and drop-down list content controls. // Assume there are 2 content controls (the console prints 2). The newly added content control is the second one. const count = await WPSOpenApi.Application.ActiveDocument.ContentControls.Count; console.log(count); // Get all options of the drop-down list. const ContentControlListEntries = await WPSOpenApi.Application.ActiveDocument.ContentControls.Item(2).DropdownListEntries; // Get the first option of this drop-down list. const DropdownListEntry1 = await ContentControlListEntries.Item(1); // Select this list option. await DropdownListEntry1.Select(); // Get the information of this list option. const SelectedItem = await DropdownListEntries.GetSelectedItem(); console.log(SelectedItem); }
-
ActiveDocument.ContentControls.Item(Index).DropdownListEntries.UnSelect()
Deselects a list option in a drop-down list content control.
This feature is supported in JS-SDK V1.1.15 and later.
-
Syntax
expression.ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Clear()expression: An Application object.
-
Examples
-
Deselect an option in a new drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const ContentControls = await app.ActiveDocument.ContentControls; // Add a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Get all list options of this drop-down list content control. const ContentControlListEntries = await ContentControl. DropdownListEntries; // Add a list option to this drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // Add a list option to this drop-down list content control. If you do not specify Value and Index, Value is the same as Text. await ContentControlListEntries.Add({ Text: 'Text 2', }); // Select the first list option of this drop-down list content control. await ContentControlListEntries.Item(1).Select(); // Unselect this list option after 3000 ms. setTimeout(async () => { await ContentControlListEntries.UnSelect(); }, 3000); } -
Deselect an option in a drop-down list content control by index
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const ContentControls = await app.ActiveDocument.ContentControls; // Add a drop-down list content control. const ContentControl = await WPSOpenApi.Application.ActiveDocument.ContentControls.Add({ Type: 4, }); // Get the number of content controls in the document, including text and drop-down list content controls. // Assume there are 2 content controls (the console prints 2). The newly added content control is the second one. const count = await WPSOpenApi.Application.ActiveDocument.ContentControls.Count; console.log(count); // Get all list options of this drop-down list content control. const DropdownListEntries = await WPSOpenApi.Application.ActiveDocument.ContentControls.Item(2).DropdownListEntries; // Get the first list option of this drop-down list content control. const DropdownListEntry1 = await DropdownListEntries.Item(1); // Select this list option. await DropdownListEntry1.Select(); // Unselect this list option after 3000 ms. setTimeout(async () => { await ContentControlListEntries.UnSelect(); }, 3000); }
-
ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Item()
Retrieves a specified option from the drop-down list entries collection.
This feature is supported in JS-SDK V1.1.15 and later.
-
Syntax
expression.ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Item(Index)expression: An Application object.
-
Parameters
Property
Data type
Required
Description
Index
Number
Yes
The index of the drop-down list option to retrieve.
-
Examples
-
Get a drop-down list option by adding a new drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // The content control object. const ContentControls = await app.ActiveDocument.ContentControls; // 1. Add a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // 2. Get the drop-down list of this content control. const ContentControlListEntries = await ContentControl. DropdownListEntries; // 3. Add an option to this control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // 3. Add an option to this control. You can omit Value and Index. If omitted, Value is the same as Text, and the option is added to the end. await ContentControlListEntries.Add({ Text: 'Text 2', }); // 4. Get the first item. const ContentControlListEntry1 = await ContentControl.DropdownListEntries.Item(1); } -
Get a drop-down list option by index
async function example() { await instance.ready(); const app = instance.Application; // The content control object. const ContentControls = await app.ActiveDocument.ContentControls; // 1. Add a drop-down list content control. const ContentControl = await app.ActiveDocument.ContentControls.Add({ Type: 4, }); // 2. Add an option to this control. await ContentControl.DropdownListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // 2. Add an option to this control. You can omit Value and Index. If omitted, Value is the same as Text, and the option is added to the end. await ContentControl.DropdownListEntries.Add({ Text: 'Text 2', }); // 3. Get the number of content controls in the document, including text and drop-down list content controls. const counts = await app.ActiveDocument.ContentControls.Count; console.log(counts); // Assume there are 2 (the console prints 2). The newly added content control is the second one. // 4. Get the drop-down list of the first drop-down list content control. const DropdownListEntries = await app.ActiveDocument.ContentControls.Item(1).DropdownListEntries; // 5. Get the first option (Text 1) of this drop-down list. const DropdownListEntry1 = await DropdownListEntries.Item(1); }
-
Properties
ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Count
Returns the total number of list options in a drop-down list content control.
This feature is supported in JS-SDK V1.1.15 and later.
-
Syntax
expression.ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Countexpression: An Application object.
-
Examples
-
Get the total number of options from a new drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const ContentControls = await app.ActiveDocument.ContentControls; // Add a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Get all list options of this drop-down list content control. const ContentControlListEntries = await ContentControl. DropdownListEntries; // Add a list option to this drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // Add a list option to this drop-down list content control. If you do not specify Value and Index, Value is the same as Text. await ContentControlListEntries.Add({ Text: 'Text 2', }); // Get the total number of list options in this drop-down list content control. const Count = await ContentControlListEntries.Count; console.log(Count); } -
Get the total number of options from a drop-down list content control by index
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const ContentControls = await app.ActiveDocument.ContentControls; // Add a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Get the number of content controls in the document, including text and drop-down list content controls. // Assume there are 2 content controls (the console prints 2). The newly added content control is the second one. const Count = await WPSOpenApi.Application.ActiveDocument.ContentControls.Count; // Get all list options of this drop-down list content control. const ContentControlListEntries = await WPSOpenApi.Application.ActiveDocument.ContentControls.Item(Count).DropdownListEntries; // Get the total number of list options in this drop-down list content control. const Count = await ContentControlListEntries.Count; console.log(Count); }
-
ContentControlListEntry
ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Item()
Retrieves a single list option from a drop-down list content control.
This feature is supported in JS-SDK V1.1.15 and later.
-
Syntax
expression.ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Item(Index)expression: An Application object.
-
Parameters
Property
Data type
Required
Description
Index
Number
Yes
The index of the drop-down list option to retrieve.
-
Examples
-
Get a single option from a new drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const ContentControls = await app.ActiveDocument.ContentControls; // Add a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Get all list options of this drop-down list content control. const ContentControlListEntries = await ContentControl. DropdownListEntries; // Add a list option to this drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // Add a list option to this drop-down list content control. If you do not specify Value and Index, Value is the same as Text. await ContentControlListEntries.Add({ Text: 'Text 2', }); // Get the first list option of this drop-down list content control. const ContentControlListEntry1 = await ContentControlListEntries.Item(1); } -
Get a single option from a drop-down list content control by index
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const ContentControls = await app.ActiveDocument.ContentControls; // Add a drop-down list content control. const ContentControl = await WPSOpenApi.Application.ActiveDocument.ContentControls.Add({ Type: 4, }); // Get the number of content controls in the document, including text and drop-down list content controls. // Assume there are 2 content controls (the console prints 2). The newly added content control is the second one. const count = await WPSOpenApi.Application.ActiveDocument.ContentControls.Count; console.log(count); // Get all list options of this drop-down list content control. const DropdownListEntries = await WPSOpenApi.Application.ActiveDocument.ContentControls.Item(2).DropdownListEntries; // Get the first list option of this drop-down list content control. const DropdownListEntry1 = await DropdownListEntries.Item(1); }
-
Methods
ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Item(Index).Delete()
Deletes a list option from a drop-down list or combo box content control.
This feature is supported in JS-SDK V1.1.15 and later.
At least one option must remain in the list. You cannot delete the last item.
-
Syntax
expression.ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Item(Index).Delete()expression: An Application object.
-
Examples
-
Delete an option from a new drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const ContentControls = await app.ActiveDocument.ContentControls; // Add a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Get all list options of this drop-down list content control. const ContentControlListEntries = await ContentControl. DropdownListEntries; // Add a list option to this drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // Add a list option to this drop-down list control. If you do not specify Value and Index, Value is the same as Text. await ContentControlListEntries.Add({ Text: 'Text 2', }); // Select the first list option of this drop-down list content control. await ContentControlListEntries.Item(1).Select(); // Delete this list option. await ContentControlListEntries.Item(1).Delete(); } -
Delete an option from a drop-down list content control by index
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const ContentControls = await app.ActiveDocument.ContentControls; // Add a drop-down list content control. const ContentControl = await WPSOpenApi.Application.ActiveDocument.ContentControls.Add({ Type: 4, }); // Get the number of content controls in the document, including text and drop-down list content controls. // Assume there are 2 content controls (the console prints 2). The newly added content control is the second one. const count = await WPSOpenApi.Application.ActiveDocument.ContentControls.Count; console.log(count); // Get all list options of this drop-down list content control. const DropdownListEntries = await WPSOpenApi.Application.ActiveDocument.ContentControls.Item(2).DropdownListEntries; // Get the first list option of this drop-down list content control. const DropdownListEntry1 = await DropdownListEntries.Item(1); // Select this list option. await DropdownListEntry1.Select(); // Delete this list option. await DropdownListEntry1.Delete(); }
-
ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Item(Index).Select()
Selects a list option in a drop-down list or combo box content control.
This feature is supported in JS-SDK V1.1.15 and later.
-
Syntax
expression.ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Item(Index).Select()expression: An Application object.
-
Examples
-
Select an option in a new drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const ContentControls = await app.ActiveDocument.ContentControls; // Add a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Get all list options of this drop-down list content control. const ContentControlListEntries = await ContentControl. DropdownListEntries; // Add a list option to this drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // Add a list option to this drop-down list control. If you do not specify Value and Index, Value is the same as Text. await ContentControlListEntries.Add({ Text: 'Text 2', }); // Select the first list option of this drop-down list content control. await ContentControlListEntries.Item(1).Select(); } -
Select an option in a drop-down list content control by index
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const ContentControls = await app.ActiveDocument.ContentControls; // Add a drop-down list content control. const ContentControl = await WPSOpenApi.Application.ActiveDocument.ContentControls.Add({ Type: 4, }); // Get the number of content controls in the document, including text and drop-down list content controls. // Assume there are 2 content controls (the console prints 2). The newly added content control is the second one. const count = await WPSOpenApi.Application.ActiveDocument.ContentControls.Count; console.log(count); // Get all list options of this drop-down list content control. const DropdownListEntries = await WPSOpenApi.Application.ActiveDocument.ContentControls.Item(2).DropdownListEntries; // Get the first list option of this drop-down list content control. const DropdownListEntry1 = await DropdownListEntries.Item(1); // Select this list option. await DropdownListEntry1.Select(); }
-
Properties
ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Item(Index).Text
Gets or sets the display text of a list option in a drop-down list or combo box content control.
This feature is supported in JS-SDK V1.1.15 and later.
-
Syntax
expression.ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Item(Index).Textexpression: An Application object.
-
Examples
-
Get the display text of an option in a new drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const ContentControls = await app.ActiveDocument.ContentControls; // Add a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Get all list options of this drop-down list content control. const ContentControlListEntries = await ContentControl. DropdownListEntries; // Add a list option to this drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // Add a list option to this drop-down list content control. If you do not specify Value and Index, Value is the same as Text. await ContentControlListEntries.Add({ Text: 'Text 2', }); // Get the display text of the first list option of this drop-down list content control. const Text = await ContentControlListEntries.Item(1).Text; console.log(Text); } -
Get the display text of an option in a drop-down list content control by index
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const ContentControls = await app.ActiveDocument.ContentControls; // Add a drop-down list content control. const ContentControl = await WPSOpenApi.Application.ActiveDocument.ContentControls.Add({ Type: 4, }); // Get the number of content controls in the document, including text and drop-down list content controls. // Assume there are 2 content controls (the console prints 2). The newly added content control is the second one. const count = await WPSOpenApi.Application.ActiveDocument.ContentControls.Count; console.log(count); // Get all list options of this drop-down list content control. const DropdownListEntries = await WPSOpenApi.Application.ActiveDocument.ContentControls.Item(2).DropdownListEntries; // Get the first list option of this drop-down list content control. const DropdownListEntry1 = await DropdownListEntries.Item(1); // Get the display text of this list option. const Text = await DropdownListEntry1.Text; console.log(Text); }
-
ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Item(Index).Value
Returns the value of a list option in a drop-down list or combo box content control.
This feature is supported in JS-SDK V1.1.15 and later.
-
Syntax
expression.ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Item(Index).Valueexpression: An Application object.
-
Examples
-
Get the value of an option in a new drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const ContentControls = await app.ActiveDocument.ContentControls; // Add a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Get all list options of this drop-down list content control. const ContentControlListEntries = await ContentControl. DropdownListEntries; // Add a list option to this drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // Add a list option to this drop-down list content control. If you do not specify Value and Index, Value is the same as Text. await ContentControlListEntries.Add({ Text: 'Text 2', }); // Get the value of the first list option in this drop-down list content control. const Value = await ContentControlListEntries.Item(1).Value; console.log(Value); } -
Get the value of an option in a drop-down list content control by index
async function example() { await instance.ready(); const app = instance.Application; // Get all content controls. const ContentControls = await app.ActiveDocument.ContentControls; // Add a drop-down list content control. const ContentControl = await WPSOpenApi.Application.ActiveDocument.ContentControls.Add({ Type: 4, }); // Add a list option to this drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // Add a list option to this drop-down list content control. If you do not specify Value and Index, Value is the same as Text. await ContentControlListEntries.Add({ Text: 'Text 2', }); // Get the number of content controls in the document, including text and drop-down list content controls. // Assume there are 2 content controls (the console prints 2). The newly added content control is the second one. const count = await WPSOpenApi.Application.ActiveDocument.ContentControls.Count; console.log(count); // Get all list options of this drop-down list content control. const DropdownListEntries = await WPSOpenApi.Application.ActiveDocument.ContentControls.Item(2).DropdownListEntries; // Get the first list option of this drop-down list content control. const DropdownListEntry1 = await DropdownListEntries.Item(1); // Get the value of this list option. const Value = await DropdownListEntry1.Value; console.log(Value); }
-