Word.ContentControlOptions interface
指定定义返回哪些内容控件的选项。
注解
示例
// 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
// Toggles the isChecked property of the first checkbox content control found in the selection.
await Word.run(async (context) => {
const selectedRange: Word.Range = context.document.getSelection();
let selectedContentControl = selectedRange
.getContentControls({
types: [Word.ContentControlType.checkBox]
})
.getFirstOrNullObject();
selectedContentControl.load("id,checkboxContentControl/isChecked");
await context.sync();
if (selectedContentControl.isNullObject) {
const parentContentControl: Word.ContentControl = selectedRange.parentContentControl;
parentContentControl.load("id,type,checkboxContentControl/isChecked");
await context.sync();
if (parentContentControl.isNullObject || parentContentControl.type !== Word.ContentControlType.checkBox) {
console.warn("No checkbox content control is currently selected.");
return;
} else {
selectedContentControl = parentContentControl;
}
}
const isCheckedBefore = selectedContentControl.checkboxContentControl.isChecked;
console.log("isChecked state before:", `id: ${selectedContentControl.id} ... isChecked: ${isCheckedBefore}`);
selectedContentControl.checkboxContentControl.isChecked = !isCheckedBefore;
selectedContentControl.load("id,checkboxContentControl/isChecked");
await context.sync();
console.log(
"isChecked state after:",
`id: ${selectedContentControl.id} ... isChecked: ${selectedContentControl.checkboxContentControl.isChecked}`
);
});
属性
types | 内容控件类型的数组,项必须是“RichText”、“PlainText”、“CheckBox”、“DropDownList”或“ComboBox”。 |
属性详细信息
types
内容控件类型的数组,项必须是“RichText”、“PlainText”、“CheckBox”、“DropDownList”或“ComboBox”。
types: Word.ContentControlType[];
属性值
注解
注意:WordApi 1.5 中添加了“PlainText”支持。 WordApi 1.7 中添加了“CheckBox”支持。 “DropDownList”和“ComboBox”支持目前处于预览状态。