Word.ContentControlType enum
Specifies supported content control types and subtypes.
Remarks
Examples
// Run a batch operation against the Word object model.
await Word.run(async (context) => {
// Create a proxy object for the content controls collection.
const contentControls = context.document.contentControls;
// Queue a command to load the id property for all of the content controls.
contentControls.load('id');
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
if (contentControls.items.length === 0) {
console.log('No content control found.');
}
else {
// Queue a command to load the properties on the first content control.
contentControls.items[0].load( 'appearance,' +
'cannotDelete,' +
'cannotEdit,' +
'color,' +
'id,' +
'placeHolderText,' +
'removeWhenEdited,' +
'title,' +
'text,' +
'type,' +
'style,' +
'tag,' +
'font/size,' +
'font/name,' +
'font/color');
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
await context.sync();
console.log('Property values of the first content control:' +
' ----- appearance: ' + contentControls.items[0].appearance +
' ----- cannotDelete: ' + contentControls.items[0].cannotDelete +
' ----- cannotEdit: ' + contentControls.items[0].cannotEdit +
' ----- color: ' + contentControls.items[0].color +
' ----- id: ' + contentControls.items[0].id +
' ----- placeHolderText: ' + contentControls.items[0].placeholderText +
' ----- removeWhenEdited: ' + contentControls.items[0].removeWhenEdited +
' ----- title: ' + contentControls.items[0].title +
' ----- text: ' + contentControls.items[0].text +
' ----- type: ' + contentControls.items[0].type +
' ----- style: ' + contentControls.items[0].style +
' ----- tag: ' + contentControls.items[0].tag +
' ----- font size: ' + contentControls.items[0].font.size +
' ----- font name: ' + contentControls.items[0].font.name +
' ----- font color: ' + contentControls.items[0].font.color);
}
});
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/10-content-controls/insert-and-change-checkbox-content-control.yaml
// Traverses each paragraph of the document and places a checkbox content control at the beginning of each.
await Word.run(async (context) => {
let paragraphs = context.document.body.paragraphs;
paragraphs.load("$none"); // Don't need any properties; just start each paragraph with a content control.
await context.sync();
for (let i = 0; i < paragraphs.items.length; i++) {
let contentControl = paragraphs.items[i]
.getRange(Word.RangeLocation.start)
.insertContentControl(Word.ContentControlType.checkBox);
}
console.log("Checkbox content controls inserted: " + paragraphs.items.length);
await context.sync();
});
Fields
buildingBlockGallery = "BuildingBlockGallery" | |
checkBox = "CheckBox" | |
comboBox = "ComboBox" | |
datePicker = "DatePicker" | |
dropDownList = "DropDownList" | |
picture = "Picture" | |
plainText = "PlainText" | |
plainTextInline = "PlainTextInline" | |
plainTextParagraph = "PlainTextParagraph" | |
repeatingSection = "RepeatingSection" | |
richText = "RichText" | Identifies a rich text content control. |
richTextInline = "RichTextInline" | |
richTextParagraphs = "RichTextParagraphs" | |
richTextTable = "RichTextTable" | Contains a whole table. |
richTextTableCell = "RichTextTableCell" | Contains a whole cell. |
richTextTableRow = "RichTextTableRow" | Contains a whole row. |
unknown = "Unknown" |
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Office Add-ins