英文:
Office.js Word API not able to read plain text type content controls
问题
我正在尝试获取文档中的所有内容控件。根据微软Word API文档,只支持RichText和纯文本类型的内容控件。但我无法获取纯文本类型的内容控件。我只能获取富文本内容控件。
const contentControls = doc.contentControls;
contentControls.load('title, tag, type');
return context.sync().then(function () {
// 遍历内容控件
console.log(contentControls.items.length);
for (let i = 0; i < contentControls.items.length; i++) {
const contentControl = contentControls.items[i];
console.log(`内容控件 #${i + 1}`);
console.log('标题:', contentControl.title);
console.log('标签:', contentControl.tag);
console.log('类型:', contentControl.type);
}
});
我尝试使用以下Word API引用:
https://appsforoffice.microsoft.com/lib/beta/hosted/office.js
或者
https://appsforoffice.microsoft.com/lib/1/hosted/office.js
但使用这两个引用都只返回富文本内容控件。我是否漏掉了什么,还是Word API仍不支持纯文本类型的内容控件?
英文:
I am trying to get all content controls present in the document. As per microsoft Word API docuemntation only RichText and plain Text type content controls are supported. But i am not able to get the plain text type content controls. I get only richtext content controls.
const contentControls = doc.contentControls;
contentControls.load('title, tag, type');
return context.sync().then(function () {
// Loop through the content controls
console.log(contentControls.items.length);
for (let i = 0; i < contentControls.items.length; i++) {
const contentControl = contentControls.items[i];
console.log(`Content Control #${i + 1}`);
console.log('Title: ', contentControl.title);
console.log('Tag: ', contentControl.tag);
console.log('Type: ', contentControl.type);
}
});
I tried using below WordAPI refrence:
https://appsforoffice.microsoft.com/lib/beta/hosted/office.js
OR
https://appsforoffice.microsoft.com/lib/1/hosted/office.js
With both refrences the result contains only richtext content controls.
Am i missing something or plain text type content controls are still not supported via word API?
答案1
得分: 3
纯文本内容控件目前在Word JavaScript API需求集1.5中受支持。请使用Document.getContentControls(options) API。将options
参数留空将获取文档中的富文本和纯文本内容控件。如果您只想要纯文本,请指定选项"PlainText"。
英文:
Plain text content controls are currently supported in Word JavaScript API requirement set 1.5. Please use Document.getContentControls(options) API. Leaving the options
parameter empty will get both rich text and plain text content controls in the document. If you want plain text only, please specify the option "PlainText".
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论