簡體   English   中英

如何訪問所選Outlook Web加載項JavaScript的字體?

[英]How can I access the font of selected, Outlook Web Add-in JavaScript?

在Word Web加載項中,我可以訪問所選的context.document.getSelection().font但我在Outlook Web Add-in中找不到它(在搜索之后),我只能獲取所選的文本通過Office.context.mailbox.item.getSelectedDataAsyncOffice.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
                });

        });
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM