图像缩略图未在2013年或2016年的桌面版中通过加载项显示在Outlook邮件正文中

时间:2017-07-26 07:51:39

标签: javascript outlook outlook-addin

图片缩略图未在2013年或2016年的桌面版中通过加载项以文本格式显示在outlook电子邮件正文中。 代码在Outlook的在线版本中运行良好,但在桌面版本的Outlook中,似乎无法使用某些图像 Issue shown 下面提到的代码段:

    try {               
            var Filename = Office.prototype.CheckExtension(imageurl);
            if (Office.context.mailbox) {
                var imageurldec = decodeURIComponent(imageurl);
                imageurldec = imageurl.replace(/\ /g, '%20');                 

                var img = '<img src=' + imageurl + ' />';
                var outlookdiv = '';
                var thumpimage = '<img src="' + thumbs + '" alt="' + imagename + '" >';

                if (assettype == 'image') {

                    outlookdiv = ' <div><a href=' + imageurldec + ' target="_blank">' + thumpimage + '</a></div>';
                    Office.prototype.OutlookImageInsert(outlookdiv, imageurl, imagename, spanid, assetid, thumbs, assettype);
                } else if (assettype == 'video') {

                    thumpimage = '<img src="' + thumbs + '" style="width:204px;height:128px;"  alt="' + imagename + '" >';
                    outlookdiv = ' <div><a href=' + imageurldec + ' target="_blank">' + thumpimage + '</a></div>';
Office.prototype.OutlookVideoInsert(outlookdiv, imageurl, imagename, spanid, assetid, thumbs, assettype);
                } else if (assettype == 'audio') {
                    thumpimage = '<img src="' + thumbs + '" style="width:204px;height:128px;"  alt="' + imagename + '" >'; outlookdiv = ' <div><a href=' + imageurldec + ' target="_blank"><div ><div ></div>' + thumpimage + '</a></div>';

                if (windowurl[1] == "Web") {

                    var appname = windowurl[0].split('_host_Info=');
                    if (appname[1].toLowerCase() == 'powerpoint' || appname[1].toLowerCase() == 'word') {
                        var base64 = Office.prototype.ImageToBase64(imageurl);
                        $.when(base64).done(function (data) {
                            if (data != null) {
                                var b64str = data.data;
                                b64str = b64str.split('data:image/png;base64,');
                                Office.context.document.setSelectedDataAsync(b64str[1], {
                                    coercionType: Office.CoercionType.Image,
                                    imageLeft: 0,
                                    imageTop: 0,
                                },
                                    function (asyncResult) {
                                        if (asyncResult.status === Office.AsyncResultStatus.Failed) {

                                        }
                                    });
                            }
                        }).fail(function (data) {
                        });
                    }
                } else {
                    Office.context.document.getSelectedDataAsync(Office.CoercionType.Html,
                        function (result) {
                            if (result.status === Office.AsyncResultStatus.Failed) {
                                var base64 = Office.prototype.ImageToBase64(imageurl);
                                $.when(base64).done(function (data) {
                                    if (data != null) {
                                        var b64str = data.data;
                                        b64str = b64str.split('data:image/png;base64,');
                                        Office.context.document.setSelectedDataAsync(b64str[1], {
                                            coercionType: Office.CoercionType.Image,
                                            imageLeft: 0,
                                            imageTop: 0,
                                        },
                                            function (asyncResult) {
                                                if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                                                    var divid = "officeinsertimg" + assetid;
                                                    var div = document.getElementById(divid);
                                                    var controlRange;
                                                    var scrollposition = $(window).scrollTop();
                                                    if (document.body.createControlRange) {
                                                        controlRange = document.body.createControlRange();
                                                        controlRange.addElement(div);
                                                        controlRange.execCommand('Copy');
                                                        controlRange.execCommand('Paste');
                                                        $('#' + spanid).css('display', 'inline');
                                                        $('#' + spanid).html('Your asset has been copied over to the clipboard , you can now paste into your document by using cntr+v or paste in the contexual menu')
                                                        setTimeout(function () {
                                                            $('#' + spanid).css('display', 'none');
                                                        }, 5000);
                                                    }
                                                    $("html, body").animate({ scrollTop: scrollposition }, "slow");
                                                }
                                            });
                                    }
                                }).fail(function (data) {
                                });


                            } else {
                                var imgHTML = "<img " + "src='" + imageurl + "'" + " alt ='apps for Office image' height='200px' width='200px' img/>";
                                Office.context.document.setSelectedDataAsync(
                                    imgHTML, { coercionType: "html" },
                                    function (asyncResult) {
                                        if (asyncResult.status == "failed") {
                                            write('Error: ' + asyncResult.error.message);
                                        }
                                    });
                            }
                        }
                    );
                }
            }
        } catch (e) {
            $('#errormessagediv').css('display', 'block');
            $('#errormessagediv').html('Error in insertion of image');
        }
    }

我很感激帮助解决了问题所在。感谢

0 个答案:

没有答案