This topic describes API operations that are related to document content controls.
ContentControls
ActiveDocument.ContentControls
Returns all the content controls in the active document.
Only JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.ContentControlsexpression: an Application object.
Examples
async function example() { await instance.ready(); const app = instance.Application; // Return all content controls in the active document. const ContentControls = await app.ActiveDocument.ContentControls; }
Methods
ActiveDocument.ContentControls.Add()
Inserts a content control at the position of the cursor.
Only JS-SDK V1.1.11 and later support this feature.
Syntax
expression.ActiveDocument.ContentControls.Add({ Type })expression: an Application object.
Parameters
Parameter
Data type
Required
Description
Type
Enum
Yes
The type of the content control. You can set this parameter to one of the constant values of WdContentControlType. If you leave this parameter empty, a content control for rich text format (RTF) is inserted.
ImportantJS-SDK V1.1.15 and later allow you to insert drop-down list content controls.
Return value
The inserted content control.
Examples
Insert an RTF content control
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const contentControls = await app.ActiveDocument.ContentControls; // Insert an RTF content control at the cursor position. await contentControls.Add(); }Insert a drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const contentControls = await app.ActiveDocument.ContentControls; // Insert a drop-down list content control at the cursor position. await contentControls.Add({ Type: 4, }); }
ActiveDocument.ContentControls.Item()
Returns the specified content control within the collection of content controls in the active document.
Only JS-SDK V1.1.11 and later support this feature.
Syntax
expression.ActiveDocument.ContentControls.Item(Index)expression: an Application object.
Parameters
Parameter
Data type
Required
Description
Index
Number
Yes
The index number of the content control to return.
Return value
The specified ContentControl object.
Examples
async function example() { await instance.ready(); const app = instance.Application; // Return the first ContentControl object. const contentControl = await app.ActiveDocument.ContentControls.Item(1); }ActiveDocument.ContentControls.SetItemsContent()
Sets multiple content controls. To call the
SetItemsContentmethod, you must addwps.enableSuperContentControlApi = trueto the jsconfig configuration file.Syntax
expression.ActiveDocument.ContentControls.SetItemsContent({Value, Key, CompareTitle })expression: an Application object.
Parameters
Parameter
Data type
Required
Description
Value
String
Yes
The content to set.
Key
String
Yes
The title or tag.
CompareTitle
Boolean
Yes
Specifies whether to perform batch setting by title. If this parameter is set to true, batch setting is performed by title. If this parameter is set to false, batch setting is performed by tag.
Examples
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 active document.
Syntax
expression.ActiveDocument.ContentControls.Countexpression: an Application object.
Return value
The number of content controls in the active document.
Examples
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const contentControls = await app.ActiveDocument.ContentControls; // Return the number of content controls. const count = await contentControls.Count; console.log(count); }
ContentControl
ActiveDocument.ContentControls.Item(Index)
Returns the specified content control.
Only JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.ContentControls.Item(Index)expression: an Application object.
Parameters
Parameter
Data type
Required
Description
Index
String
Yes
The ordinal position of the content control to return.
Return value
The specified content control.
Examples
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const contentControls = await app.ActiveDocument.ContentControls; // Return the first ContentControl object. const contentControl = await contentControls.Item(1); }
ActiveDocument.ContentControls.Item(Index).SetPlaceholderText()
Sets the placeholder text for the specified content control.
Syntax
expression.ActiveDocument.ContentControls.Item(Index).SetPlaceholderText({ Text })expression: an Application object.
Parameters
Parameter
Data type
Required
Description
Text
String
Yes
The placeholder text for the specified content control.
Examples
//@file=base.docx async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls. const contentControls = await app.ActiveDocument.ContentControls; // Return 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 for a content control.
Only JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.ContentControls.Item(Index).PlaceholderTextexpression: an Application object.
Examples
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const contentControls = await app.ActiveDocument.ContentControls; // Return the first ContentControl object. const contentControl = await contentControls.Item(1); // Return the placeholder text for the content control. const placeholderText = await contentControl.PlaceholderText; console.log(placeholderText); }
ActiveDocument.ContentControls.Item(Index).Range
Returns a Range object that represents the content of the content control. You can use Range.Text to set or return the text for a Range object in a content control.
JS-SDK V1.1.12 and later support this feature.
Syntax
expression.ActiveDocument.ContentControls.Item(Index).Rangeexpression: an Application object.
Examples
Return the range of a ContentControl object
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const contentControls = await app.ActiveDocument.ContentControls; // Return the first ContentControl object. const contentControl = await contentControls.Item(1); // Return the range of the content control. const range = await contentControl.Range; console.log(range); }Return and set the text in a ContentControl object
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const contentControls = await app.ActiveDocument.ContentControls; // Return the first ContentControl object. const contentControl = await contentControls.Item(1); // Return the range of the content control. const range = await contentControl.Range; // Return the text in the content control. const text = range.Text; console.log(text); // Set the text for the content control. range.Text = 'Aliyun'; }
ActiveDocument.ContentControls.Item(Index).Tag
Sets or returns the tag of a content control.
Only JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.ContentControls.Item(Index).Tagexpression: an Application object.
Examples
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const contentControls = await app.ActiveDocument.ContentControls; // Return the first ContentControl object. const contentControl = await contentControls.Item(1); // Set a tag for the content control. contentControl.Tag = 'Aliyun'; // Return the tag of the content control. const Tag = await contentControl.Tag; console.log(Tag); }
ActiveDocument.ContentControls.Item(Index).Title
Sets or returns the title for a content control.
Only JS-SDK V1.1.10 and later support this feature.
Syntax
expression.ActiveDocument.ContentControls.Item(Index).Titleexpression: an Application object.
Examples
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const contentControls = await app.ActiveDocument.ContentControls; // Return the first ContentControl object. const contentControl = await contentControls.Item(1); // Set a title for the content control. contentControl.Title = 'Aliyun'; // Return the title of the content control. const title = await contentControl.Title; console.log(title);
ContentControlListEntries
ActiveDocument.ContentControls.Item(Index).DropdownListEntries
Returns all items in a drop-down list content control. This property is read-only.
Only JS-SDK V1.1.15 and later support this feature.
Syntax
expression.ActiveDocument.ContentControls.Item(Index).DropdownListEntriesexpression: an Application object.
Examples
Insert a drop-down list content control and return all items in the content control
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const ContentControls = await app.ActiveDocument.ContentControls; // Insert a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Return all items in the drop-down list content control. const ContentControlListEntries = await ContentControl. DropdownListEntries; }Return all items in an existing drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const ContentControls = await app.ActiveDocument.ContentControls; // Insert a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Return the number of content controls in the document (including text and drop-down list content controls). // If the number of content controls is 2 after insertion (the count result printed to the console is 2), the index of the new content control is 2. const Count = await WPSOpenApi.Application.ActiveDocument.ContentControls.Count; // Return all items in the drop-down list content control. const ContentControlListEntries = await WPSOpenApi.Application.ActiveDocument.ContentControls.Item(Count).DropdownListEntries; }
Methods
ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Add()
Adds an item to a drop-down list or combo box content control and returns a ContentControlListEntry object that represents the item added to the drop-down list or combo box content control.
Only JS-SDK V1.1.15 and later support this feature.
Syntax
expression.ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Add({ Text, Value, Index })expression: an Application object.
Examples
Add items to a drop-down list content control when you insert the content control
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const ContentControls = await app.ActiveDocument.ContentControls; // Insert a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Return all items in the drop-down list content control. const ContentControlListEntries = await ContentControl. DropdownListEntries; // Add an item to the drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // Add another item to the drop-down list content control. The Value and Index parameters are optional. If you leave the Value parameter unspecified, the Value parameter has the same value as the Text parameter. await ContentControlListEntries.Add({ Text: 'Text 2', }); }Add an item to an existing drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const ContentControls = await app.ActiveDocument.ContentControls; // Insert a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Return the number of content controls in the document (including text and drop-down list content controls). // If the number of content controls is 2 after insertion (the count result printed to the console is 2), the index of the new content control is 2. const Count = await WPSOpenApi.Application.ActiveDocument.ContentControls.Count; // Return all items in the drop-down list content control. const ContentControlListEntries = await WPSOpenApi.Application.ActiveDocument.ContentControls.Item(Count).DropdownListEntries; // Add an item to the drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); }
ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Clear()
Deletes all items from a drop-down list or combo box content control.
Only JS-SDK V1.1.15 and later support this feature.
Syntax
expression.ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Clear()expression: an Application object.
Examples
Insert a drop-down list content control and delete all items from the drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const ContentControls = await app.ActiveDocument.ContentControls; // Insert a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Return all items in the drop-down list content control. const ContentControlListEntries = await ContentControl. DropdownListEntries; // Add an item to the drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // Add another item to the drop-down list content control. If you do not specify the Value parameter for the item, the Value parameter has the same value as the Text parameter. await ContentControlListEntries.Add({ Text: 'Text 2', }); // Delete all items from the drop-down list content control 3,000 milliseconds after it is created. setTimeout(async () => { await ContentControlListEntries.Clear(); }, 3000); }Delete all items from an existing drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const ContentControls = await app.ActiveDocument.ContentControls; // Insert a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Return the number of content controls in the document (including text and drop-down list content controls). // If the number of content controls is 2 after insertion (the count result printed to the console is 2), the index of the new content control is 2. const Count = await WPSOpenApi.Application.ActiveDocument.ContentControls.Count; // Return all items in the drop-down list content control. const ContentControlListEntries = await WPSOpenApi.Application.ActiveDocument.ContentControls.Item(Count).DropdownListEntries; // Add an item to the drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // Delete all items from the drop-down list content control 3,000 milliseconds after it is created. setTimeout(async () => { await ContentControlListEntries.Clear(); }, 3000); }
ActiveDocument.ContentControls.Item(Index).DropdownListEntries.GetSelectedItem()
Returns the selected item in a drop-down list content control.
Only JS-SDK V1.1.15 and later support this feature.
Syntax
expression.ActiveDocument.ContentControls.Item(Index).DropdownListEntries.GetSelectedItem()expression: an Application object.
Examples
Insert a drop-down list content control and return the selected item in the content control
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const ContentControls = await app.ActiveDocument.ContentControls; // Insert a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Return all items in the drop-down list content control. const ContentControlListEntries = await ContentControl. DropdownListEntries; // Add an item to the drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // Add another item to the drop-down list content control. If you do not specify the Value parameter for the item, the Value parameter has the same value as the Text parameter. await ContentControlListEntries.Add({ Text: 'Text 2', }); // Select the first item in the drop-down list content control. await ContentControlListEntries.Item(1).Select(); // Return information about the item. const SelectedItem = await DropdownListEntries.GetSelectedItem(); console.log(SelectedItem); }Return the selected item in an existing drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const ContentControls = await app.ActiveDocument.ContentControls; // Insert a drop-down list content control. const ContentControl = await WPSOpenApi.Application.ActiveDocument.ContentControls.Add({ Type: 4, }); // Return the number of content controls in the document (including text and drop-down list content controls). // If the number of content controls is 2 after insertion (the count result printed to the console is 2), the index of the new content control is 2. const count = await WPSOpenApi.Application.ActiveDocument.ContentControls.Count; console.log(count); // Return all items in the drop-down list. const ContentControlListEntries = await WPSOpenApi.Application.ActiveDocument.ContentControls.Item(2).DropdownListEntries; // Return the first item in the drop-down list. const DropdownListEntry1 = await ContentControlListEntries.Item(1); // Select the first item. await DropdownListEntry1.Select(); // Return information about the item. const SelectedItem = await DropdownListEntries.GetSelectedItem(); console.log(SelectedItem); }
ActiveDocument.ContentControls.Item(Index).DropdownListEntries.UnSelect()
Clears an item in a drop-down list content control.
Only JS-SDK V1.1.15 and later support this feature.
Syntax
expression.ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Clear()expression: an Application object.
Examples
Insert a drop-down list content control and clear an item in the content control
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const ContentControls = await app.ActiveDocument.ContentControls; // Insert a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Return all items in the drop-down list content control. const ContentControlListEntries = await ContentControl. DropdownListEntries; // Add an item to the drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // Add another item to the drop-down list content control. If you do not specify the Value parameter for the item, the Value parameter has the same value as the Text parameter. await ContentControlListEntries.Add({ Text: 'Text 2', }); // Select the first item in the drop-down list content control. await ContentControlListEntries.Item(1).Select(); // Clear the item after 3,000 milliseconds. setTimeout(async () => { await ContentControlListEntries.UnSelect(); }, 3000); }Clear an item in an existing drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const ContentControls = await app.ActiveDocument.ContentControls; // Insert a drop-down list content control. const ContentControl = await WPSOpenApi.Application.ActiveDocument.ContentControls.Add({ Type: 4, }); // Return the number of content controls in the document (including text and drop-down list content controls). // If the number of content controls is 2 after insertion (the count result printed to the console is 2), the index of the new content control is 2. const count = await WPSOpenApi.Application.ActiveDocument.ContentControls.Count; console.log(count); // Return all items in the drop-down list content control. const DropdownListEntries = await WPSOpenApi.Application.ActiveDocument.ContentControls.Item(2).DropdownListEntries; // Return the first item in the drop-down list content control. const DropdownListEntry1 = await DropdownListEntries.Item(1); // Select the first item. await DropdownListEntry1.Select(); // Clear the item after 3,000 milliseconds. setTimeout(async () => { await ContentControlListEntries.UnSelect(); }, 3000); }
ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Item()
Returns an item in the item collection.
Only JS-SDK V1.1.15 and later support this feature.
Syntax
expression.ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Item(Index)expression: an Application object.
Parameters
Parameter
Data type
Required
Description
Index
Number
Yes
The index number of the item to return.
Examples
Insert a drop-down list content control and return an item in the content control
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls. const ContentControls = await app.ActiveDocument.ContentControls; // 1. Insert a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // 2. Return all items in the drop-down list content control. const ContentControlListEntries = await ContentControl. DropdownListEntries; // 3. Add an item to the content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // 3. Add another item to the content control. The Value and Index parameters are optional. If you leave the Value parameter unspecified, the Value parameter has the same value as the Text parameter. If you leave Index empty, the content control is added at the end position. await ContentControlListEntries.Add({ Text: 'Text 2', }); // 4. Return the first item. const ContentControlListEntry1 = await ContentControl.DropdownListEntries.Item(1); }Return an item in an existing content control
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls. const ContentControls = await app.ActiveDocument.ContentControls; // 1. Insert a drop-down list content control. const ContentControl = await app.ActiveDocument.ContentControls.Add({ Type: 4, }); // 2. Add an item to the content control. await ContentControl.DropdownListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // 2. Add another item to the content control. The Value and Index parameters are optional. If you leave the Value parameter unspecified, the Value parameter has the same value as the Text parameter. If you leave Index empty, the content control is added at the end position. await ContentControl.DropdownListEntries.Add({ Text: 'Text 2', }); // 3. Return the number of content controls in the document (including text and drop-down content controls). const counts = await app.ActiveDocument.ContentControls.Count; console.log(counts); // If the number of content controls in the document is 2 (the count result printed to the console is 2), the index of the new content control is 2. // 4. Return the items in the first drop-down content control. const DropdownListEntries = await app.ActiveDocument.ContentControls.Item(1).DropdownListEntries; // 5. Return the first item (Text 1) in the drop-down list content control. const DropdownListEntry1 = await DropdownListEntries.Item(1); }
Properties
ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Count
Returns the total number of items in a drop-down list content control.
Only JS-SDK V1.1.15 and later support this feature.
Syntax
expression.ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Countexpression: an Application object.
Examples
Insert a drop-down list content control and return the total number of items in the content control
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const ContentControls = await app.ActiveDocument.ContentControls; // Insert a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Return all items in the drop-down list content control. const ContentControlListEntries = await ContentControl. DropdownListEntries; // Add an item to the drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // Add an item to the drop-down list content control. The Value and Index parameters are optional. If you leave the Value parameter unspecified, the Value parameter has the same value as the Text parameter. If you leave Index empty, the content control is added at the end position. await ContentControlListEntries.Add({ Text: 'Text 2', }); // Return the total number of items in the drop-down list content control. const Count = await ContentControlListEntries.Count; console.log(Count); }Return the total number of items in an existing drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const ContentControls = await app.ActiveDocument.ContentControls; // Insert a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Return the number of content controls in the document (including text and drop-down list content controls). // If the number of content controls is 2 after insertion (the count result printed to the console is 2), the index of the new content control is 2. const Count = await WPSOpenApi.Application.ActiveDocument.ContentControls.Count; // Return all items in the drop-down list content control. const ContentControlListEntries = await WPSOpenApi.Application.ActiveDocument.ContentControls.Item(Count).DropdownListEntries; // Return the total number of items in the drop-down list content control. const Count = await ContentControlListEntries.Count; console.log(Count); }
ContentControlListEntry
ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Item()
Returns an item in a drop-down list content control.
Only JS-SDK V1.1.15 and later support this feature.
Syntax
expression.ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Item(Index)expression: an Application object.
Parameters
Parameter
Data type
Required
Description
Index
Number
Yes
The index number of the item to return.
Examples
Insert a drop-down list content control and return an item in the content control
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const ContentControls = await app.ActiveDocument.ContentControls; // Insert a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Return all items in the drop-down list content control. const ContentControlListEntries = await ContentControl. DropdownListEntries; // Add an item to the drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // Add another item to the drop-down list content control. The Value and Index parameters are optional. If you leave the Value parameter unspecified, the Value parameter has the same value as the Text parameter. await ContentControlListEntries.Add({ Text: 'Text 2', }); // Return the first item in the drop-down list content control. const ContentControlListEntry1 = await ContentControlListEntries.Item(1); }Return an item in an existing drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const ContentControls = await app.ActiveDocument.ContentControls; // Insert a drop-down list content control. const ContentControl = await WPSOpenApi.Application.ActiveDocument.ContentControls.Add({ Type: 4, }); // Return the number of content controls in the document (including text and drop-down list content controls). // If the number of content controls is 2 after insertion (the count result printed to the console is 2), the index of the new content control is 2. const count = await WPSOpenApi.Application.ActiveDocument.ContentControls.Count; console.log(count); // Return all items in the drop-down list content control. const DropdownListEntries = await WPSOpenApi.Application.ActiveDocument.ContentControls.Item(2).DropdownListEntries; // Return the first item in the drop-down list content control. const DropdownListEntry1 = await DropdownListEntries.Item(1); }
Methods
ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Item(Index).Delete()
Deletes an item from a drop-down list or combo box content control.
Only JS-SDK V1.1.15 and later support this feature.
If you call the method to delete an item from a content control, at least one item is retained in the content control.
Syntax
expression.ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Item(Index).Delete()expression: an Application object.
Examples
Insert a drop-down list content control and delete an item from the content control
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const ContentControls = await app.ActiveDocument.ContentControls; // Insert a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Return all items in the drop-down list content control. const ContentControlListEntries = await ContentControl. DropdownListEntries; // Add an item to the drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // Add another item to the drop-down list content control. If you do not specify the Value parameter for the item, the Value parameter has the same value as the Text parameter. await ContentControlListEntries.Add({ Text: 'Text 2', }); // Select the first item in the drop-down list content control. await ContentControlListEntries.Item(1).Select(); // Delete the item. await ContentControlListEntries.Item(1).Delete(); }Delete an item from an existing drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const ContentControls = await app.ActiveDocument.ContentControls; // Insert a drop-down list content control. const ContentControl = await WPSOpenApi.Application.ActiveDocument.ContentControls.Add({ Type: 4, }); // Return the number of content controls in the document (including text and drop-down list content controls). // If the number of content controls is 2 after insertion (the count result printed to the console is 2), the index of the new content control is 2. const count = await WPSOpenApi.Application.ActiveDocument.ContentControls.Count; console.log(count); // Return all items in the drop-down list content control. const DropdownListEntries = await WPSOpenApi.Application.ActiveDocument.ContentControls.Item(2).DropdownListEntries; // Return the first item in the drop-down list content control. const DropdownListEntry1 = await DropdownListEntries.Item(1); // Select the first item. await DropdownListEntry1.Select(); // Delete the item. await DropdownListEntry1.Delete(); }
ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Item(Index).Select()
Selects an item in a drop-down list or combo box content control.
Only JS-SDK V1.1.15 and later support this feature.
Syntax
expression.ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Item(Index).Select()expression: an Application object.
Examples
Insert a drop-down list content control and select an item in the content control
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const ContentControls = await app.ActiveDocument.ContentControls; // Insert a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Return all items in the drop-down list content control. const ContentControlListEntries = await ContentControl. DropdownListEntries; // Add an item to the drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // Add another item to the drop-down list content control. If you do not specify the Value parameter for the item, the Value parameter has the same value as the Text parameter. await ContentControlListEntries.Add({ Text: 'Text 2', }); // Select the first item in the drop-down list content control. await ContentControlListEntries.Item(1).Select(); }Select an item in an existing drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const ContentControls = await app.ActiveDocument.ContentControls; // Insert a drop-down list content control. const ContentControl = await WPSOpenApi.Application.ActiveDocument.ContentControls.Add({ Type: 4, }); // Return the number of content controls in the document (including text and drop-down list content controls). // If the number of content controls is 2 after insertion (the count result printed to the console is 2), the index of the new content control is 2. const count = await WPSOpenApi.Application.ActiveDocument.ContentControls.Count; console.log(count); // Return all items in the drop-down list content control. const DropdownListEntries = await WPSOpenApi.Application.ActiveDocument.ContentControls.Item(2).DropdownListEntries; // Return the first item in the drop-down list content control. const DropdownListEntry1 = await DropdownListEntries.Item(1); // Select the first item. await DropdownListEntry1.Select(); }
Properties
ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Item(Index).Text
Sets or returns the display text of an item in a drop-down list or combo box content control.
Only JS-SDK V1.1.15 and later support this feature.
Syntax
expression.ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Item(Index).Textexpression: an Application object.
Examples
Insert a drop-down list content control and return the display text of an item in the content control
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const ContentControls = await app.ActiveDocument.ContentControls; // Insert a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Return all items in the drop-down list content control. const ContentControlListEntries = await ContentControl. DropdownListEntries; // Add an item to the drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // Add another item to the drop-down list content control. If you do not specify the Value parameter for the item, the Value parameter has the same value as the Text parameter. await ContentControlListEntries.Add({ Text: 'Text 2', }); // Return the display text of the first item in the drop-down list content control. const Text = await ContentControlListEntries.Item(1).Text; console.log(Text); }Return the display text of an item in an existing drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Return all the content controls in the active document. const ContentControls = await app.ActiveDocument.ContentControls; // Insert a drop-down list content control. const ContentControl = await WPSOpenApi.Application.ActiveDocument.ContentControls.Add({ Type: 4, }); // Return the number of content controls in the document (including text and drop-down list content controls). // If the number of content controls is 2 after insertion (the count result printed to the console is 2), the index of the new content control is 2. const count = await WPSOpenApi.Application.ActiveDocument.ContentControls.Count; console.log(count); // Return all items in the drop-down list content control. const DropdownListEntries = await WPSOpenApi.Application.ActiveDocument.ContentControls.Item(2).DropdownListEntries; // Return the first item in the drop-down list content control. const DropdownListEntry1 = await DropdownListEntries.Item(1); // Return the display text of the item. const Text = await DropdownListEntry1.Text; console.log(Text); }
ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Item(Index).Value
Returns the value of an item in a drop-down list or combo box content control.
Only JS-SDK V1.1.15 and later support this feature.
Syntax
expression.ActiveDocument.ContentControls.Item(Index).DropdownListEntries.Item(Index).Valueexpression: an Application object.
Examples
Insert a drop-down list content control and return the value of an item in the drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Return all content controls in the active document. const ContentControls = await app.ActiveDocument.ContentControls; // Insert a drop-down list content control. const ContentControl = await ContentControls.Add({ Type: 4, }); // Return all items in the drop-down list content control. const ContentControlListEntries = await ContentControl. DropdownListEntries; // Add an item to the drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // Add another item to the drop-down list content control. If you do not specify the Value parameter for the item, the Value parameter has the same value as the Text parameter. await ContentControlListEntries.Add({ Text: 'Text 2', }); // Return the value of the first item in the drop-down list content control. const Value = await ContentControlListEntries.Item(1).Value; console.log(Value); }Return the value of an item in an existing drop-down list content control
async function example() { await instance.ready(); const app = instance.Application; // Return all content controls in the active document. const ContentControls = await app.ActiveDocument.ContentControls; // Insert a drop-down list content control. const ContentControl = await WPSOpenApi.Application.ActiveDocument.ContentControls.Add({ Type: 4, }); // Add an item to the drop-down list content control. await ContentControlListEntries.Add({ Text: 'Text 1', Value: 'Value 1', Index: 1, }); // Add another item to the drop-down list content control. If you do not specify the Value parameter for the item, the Value parameter has the same value as the Text parameter. await ContentControlListEntries.Add({ Text: 'Text 2', }); // Return the number of content controls in the document (including text and drop-down list content controls). // If the number of content controls is 2 after insertion (the count result printed to the console is 2), the index of the new content control is 2. const count = await WPSOpenApi.Application.ActiveDocument.ContentControls.Count; console.log(count); // Return all items in the drop-down list content control. const DropdownListEntries = await WPSOpenApi.Application.ActiveDocument.ContentControls.Item(2).DropdownListEntries; // Return the first item in the drop-down list content control. const DropdownListEntry1 = await DropdownListEntries.Item(1); // Return the value of the item. const Value = await DropdownListEntry1.Value; console.log(Value); }