在 Word Web 插件中,我可以访问所选 context.document.getSelection().font
的字体,但我在 Outlook Web 插件中找不到它(也在搜索之后)-在,我只能通过 Office.context.mailbox.item.getSelectedDataAsync
和 Office.CoercionType.Text
参数获取所选的文本,请问如何获取字体?
最佳答案
Outlook 中的文本格式是在 HTML 中完成的(假设格式不是纯文本)。您可以使用 Office.CoercionType.Html
返回基础 HTML:
Office.initialize = function () {
Office.context.mailbox.item
.getSelectedDataAsync(Office.CoercionType.Html, {},
function (asyncResult) {
var htmlData = asyncResult.value.data;
// do stuff
});
}
由于 HTML 格式设置可能超出了您的选择范围,您可能还想抓取整个正文。然后,您可以使用 getSelectedDataAsync
结果在完整的 HTML 正文中查找当前选择:
function myFunction() {
// Get the selected text
Office.context.mailbox.item
.getSelectedDataAsync('html', {}, function (asyncResult) {
// Get the full body and pass through the selectedData
// in the asyncContext.
Office.context.mailbox.item.body.getAsync("html", {
asyncContext: asyncResult.value.data
},
function callback(asyncResult) {
// Get the body from the result
let bodyDaya = asyncResult.value.data;
// Get the selectedData we passed in
let selectedData = asyncResult.asyncContext;
// Do stuff
});
});
}
关于javascript - 如何访问所选 Outlook Web 插件 JavaScript 的字体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48989919/