简体   繁体   中英

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参数,我该如何获取字体?

Text formatting in Outlook is done in HTML (assuming the format isn't plain text). You can return the underlying HTML using Office.CoercionType.Html :

Office.initialize = function () {
    Office.context.mailbox.item
        .getSelectedDataAsync(Office.CoercionType.Html, {},
            function (asyncResult) {
                var htmlData = asyncResult.value.data;
                // do stuff
            });
}

Since the HTML formatting might have been set outside the scope of your selection, you might want to grab the entire body as well. You can then use the getSelectedDataAsync results to find the current selection within the full HTML body:

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
                });

        });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM