在Word Web加载项中,我可以访问所选context.document.getSelection().font
的字体,但我在Outlook Web Add-in中找不到它(在搜索之后),我只能获取由Office.context.mailbox.item.getSelectedDataAsync
选择Office.CoercionType.Text
参数,我该如何获取字体?
答案 0 :(得分:3)
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
});
});
}