Word.ContentControlType enum
指定支持的内容控件类型和子类型。
注解
示例
// 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();
});
字段
| buildingBlockGallery = "BuildingBlockGallery" | 构建基块库内容控件 (类型和子类型) 。 |
| checkBox = "CheckBox" | 复选框内容控件 (类型和子类型) 。 |
| comboBox = "ComboBox" | 组合框内容控件 (类型和子类型) 。 |
| datePicker = "DatePicker" | 日期选取器内容控件 (类型和子类型) 。 |
| dropDownList = "DropDownList" | 下拉列表内容控件 (类型和子类型) 。 |
| group = "Group" | 组内容控件类型。 |
| picture = "Picture" | 图片内容控件 (类型和子类型) 。 |
| plainText = "PlainText" | 纯文本内容控件类型。 |
| plainTextInline = "PlainTextInline" | 包含内联元素的纯文本内容控件子类型。 |
| plainTextParagraph = "PlainTextParagraph" | 包含段落的纯文本内容控件子类型。 |
| repeatingSection = "RepeatingSection" | 重复节内容控件 (类型和子类型) 。 |
| richText = "RichText" | 格式文本内容控件类型。 |
| richTextInline = "RichTextInline" | 包含内联元素的富文本内容控件子类型。 |
| richTextParagraphs = "RichTextParagraphs" | 包含段落的富文本内容控件子类型。 |
| richTextTable = "RichTextTable" | 包含整个表的富文本内容控件子类型。 |
| richTextTableCell = "RichTextTableCell" | 包含整个单元格的富文本内容控件子类型。 |
| richTextTableRow = "RichTextTableRow" | 包含整行的富文本内容控件子类型。 |
| unknown = "Unknown" | 未知的内容控件类型。 |