如何访问所选 Outlook Web 插件 JavaScript 的字体?
How can I access the font of selected, Outlook Web Add-in JavaScript?
在 Word Web 插件中我可以访问选定的字体 context.document.getSelection().font
但我在 Outlook Web 插件中找不到它(在搜索之后),我只能得到文本由 Office.context.mailbox.item.getSelectedDataAsync
使用 Office.CoercionType.Text
参数选择,请问如何获取字体?
Outlook 中的文本格式在 HTML 中完成(假设格式不是纯文本)。您可以 return 基础 HTML 使用 Office.CoercionType.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
});
});
}
在 Word Web 插件中我可以访问选定的字体 context.document.getSelection().font
但我在 Outlook Web 插件中找不到它(在搜索之后),我只能得到文本由 Office.context.mailbox.item.getSelectedDataAsync
使用 Office.CoercionType.Text
参数选择,请问如何获取字体?
Outlook 中的文本格式在 HTML 中完成(假设格式不是纯文本)。您可以 return 基础 HTML 使用 Office.CoercionType.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
});
});
}