Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Fonts outlook签名行中的Arial字体在插入时更改为times new romance_Fonts_Outlook_Xml Signature_Outlook Web Addins - Fatal编程技术网

Fonts outlook签名行中的Arial字体在插入时更改为times new romance

Fonts outlook签名行中的Arial字体在插入时更改为times new romance,fonts,outlook,xml-signature,outlook-web-addins,Fonts,Outlook,Xml Signature,Outlook Web Addins,我正在使用Office.js在撰写邮件时插入签名。我的问题是,在第一次插入时,它会将字体和字体大小更改为错误的值,并且如果我再次插入它或插入其他签名,它将正确插入。 在此特定示例中,Outlook中的所有设置都设置为Arial 11,我要插入的签名也是Arial 11 function mergeAndInsertHtmlTemplate(_html, _json, isSignature, templateId, onDoneCallback, directMerge) { g

我正在使用Office.js在撰写邮件时插入签名。我的问题是,在第一次插入时,它会将字体和字体大小更改为错误的值,并且如果我再次插入它或插入其他签名,它将正确插入。 在此特定示例中,Outlook中的所有设置都设置为Arial 11,我要插入的签名也是Arial 11

function mergeAndInsertHtmlTemplate(_html, _json, isSignature, templateId, onDoneCallback, directMerge) {
        getMailBody(function (_htmlBody) {
            if (!_htmlBody.startsWith("<template>")) {
                var t = document.createElement("template");
                t.innerHTML = _htmlBody;
                _htmlBody = t.outerHTML;
            }

            // template html merged with data
            var _mergedHtml = mergeHtmlAndJson(_html, _json);
            if (isSignature) {
                var mergedSignature = mergeHtmlSignature(_htmlBody, _mergedHtml);
                if (mergedSignature.succeeded) {
                    updateMailBody(mergedSignature.html, function (result) {
                        factory.PrependData("");
                    });
                }
                else {
                    insertAtCursorLocation(_mergedHtml); // insert at cursor location
                }
            }
            else {
                if (Object.keys(_json).length > 0 && !directMerge) {
                    _mergedHtml = mergeMustachAndJson(_htmlBody, _json, true);
                    updateMailBody(_mergedHtml);
                }
                else {
                    _mergedHtml = mergeMustachAndJson(_html, _json);
                    insertAtCursorLocation(_mergedHtml);
                }
            }
            if (onDoneCallback) onDoneCallback();
        });
    }

function mergeHtmlSignature(mailBodyHtml, signatureHtml) {

        if (!mailBodyHtml.startsWith("<template>")) {
            var t = document.createElement("template");
            t.innerHTML = mailBodyHtml;
            mailBodyHtml = t.outerHTML;
        }

        var $mailBody = $(mailBodyHtml);
        var endComposeIndex = $mailBody.find("*").index($mailBody.find('a[name=_MailEndCompose]'));
        // $mailBody.find('[style*="_MailAutoSig"]').parent().not('div').empty(); // tryout: signature inserted twice 
        var toRemove = [];
        $mailBody.find('*[class*=iw-signature]:not(:has(a[name=_MailAutoSig]))').each(function () {
            var thisIndex = $mailBody.find("*").index($(this));
            if(endComposeIndex < 0 || thisIndex < endComposeIndex){//if ($(this).prevAll().filter("a[name=_MailEndCompose]").length == 0) {
                var parentTables = $(this).parents("table");
                toRemove.push(parentTables);
                toRemove.unshift($(this));
            }
        });

        for (var i = 0; i < toRemove.length; i++) {
            toRemove[i].remove();
        }

        $mailBody.find('[style*="_MailAutoSig"]').each(function () {
            var parentTables = $(this).parents("table");
            toRemove.push(parentTables);
            $(this).remove();
        });

        for (var i = 0; i < toRemove.length; i++) {
            toRemove[i].remove();
        }

        var _signatureLocations = $mailBody.find('a[name=_MailAutoSig]');

        if (_signatureLocations && _signatureLocations.length > 0) {
            _signatureLocations.parent().empty().html(signatureHtml);
            return { html: $mailBody[0].outerHTML, succeeded: true }
        }
        else {
            $log.warn('No signature location to insert signature. Inserting at cursor location');
            return { html: signatureHtml, succeeded: false };
        }
    }

function insertAtCursorLocation(data) {
        if (factory.BodyType === MailBody.HTML) {
            // Body is of HTML type. Specify HTML in the coercionType parameter of setSelectedDataAsync.
            Office.context.mailbox.item.body.setSelectedDataAsync(data,
                {
                    coercionType: Office.CoercionType.Html,
                    asyncContext: { var3: 1, var4: 2 }
                },
                function (asyncResult) {
                    if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                        $log.error(asyncResult.error.message);
                    }
                });
        }
        else {
            Office.context.mailbox.item.body.setSelectedDataAsync(data,
                {
                    coercionType: Office.CoercionType.Text,
                    asyncContext: { var3: 1, var4: 2 }
                },
                function (asyncResult) {
                    if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                        $log.error(asyncResult.error.message);
                    }
                });
        }
    }

function updateMailBody(data, callback) {
        Office.context.mailbox.item.body.setAsync(data, { coercionType: factory.BodyType }, function (result) {
            if (callback) callback(result);
        });
    }
函数mergeAndInsertHtmlTemplate(_html、_json、isSignature、templateId、onDoneCallback、directMerge){
getMailBody(函数(\u htmlBody){
if(!\u htmlBody.startsWith(“”){
var t=document.createElement(“模板”);
t、 innerHTML=_htmlBody;
_htmlBody=t.outerHTML;
}
//模板html与数据合并
var\u mergedHtml=mergeHtmlAndJson(\u html,\u json);
if(i签名){
var mergedSignature=mergeHtmlSignature(_htmlBody,_mergedHtml);
如果(合并签名。成功){
UpdateEmailBody(mergedSignature.html,函数(结果){
factory.PrependData(“”);
});
}
否则{
insertAtCursorLocation(_mergedHtml);//在光标位置插入
}
}
否则{
if(Object.keys(_json).length>0&&!directMerge){
_mergedHtml=mergeMustachAndJson(_htmlBody,_json,true);
updateEmailBody(_mergedHtml);
}
否则{
_mergedHtml=mergeMustachAndJson(_html,_json);
插入库位置(_mergedHtml);
}
}
if(onDoneCallback)onDoneCallback();
});
}
函数合并HtmlSignature(mailBodyHtml、signatureHtml){
如果(!mailBodyHtml.startsWith(“”){
var t=document.createElement(“模板”);
t、 innerHTML=mailBodyHtml;
mailBodyHtml=t.outerHTML;
}
var$mailBody=$(mailBodyHtml);
var-endComposeIndex=$mailBody.find(“*”).index($mailBody.find('a[name=\u mailendcomose]');
//$mailBody.find('[style*=“\u MailAutoSig”]')).parent().not('div').empty();//试用:签名插入两次
var-toRemove=[];
$mailBody.find('*[class*=iw signature]:not(:has(a[name=\u MailAutoSig])))。每个(函数(){
var thisIndex=$mailBody.find(“*”).index($(this));
if(endComposeIndex<0 | | thisIndex0){
_signatureLocations.parent().empty().html(signatureHtml);
返回{html:$mailBody[0]。outerHTML,successed:true}
}
否则{
$log.warn('没有要插入签名的签名位置。在光标位置插入');
返回{html:signatureHtml,successed:false};
}
}
函数insertAtCursorLocation(数据){
if(factory.BodyType==MailBody.HTML){
//正文为HTML类型。请在setSelectedDataAsync的强制类型参数中指定HTML。
Office.context.mailbox.item.body.setSelectedDataAsync(数据,
{
强制类型:Office.胁迫类型.Html,
asyncContext:{var3:1,var4:2}
},
函数(异步结果){
if(asyncResult.status==Office.AsyncResultStatus.Failed){
$log.error(asyncResult.error.message);
}
});
}
否则{
Office.context.mailbox.item.body.setSelectedDataAsync(数据,
{
强制类型:Office.胁迫类型.Text,
asyncContext:{var3:1,var4:2}
},
函数(异步结果){
if(asyncResult.status==Office.AsyncResultStatus.Failed){
$log.error(asyncResult.error.message);
}
});
}
}
函数updateEmailBody(数据,回调){
Office.context.mailbox.item.body.setAsync(数据,{强制类型:factory.BodyType},函数(结果){
如果(回调)回调(结果);
});
}
这是我要插入的签名:

<div>
<a name="_MailAutoSig">
    <div class="iw-signature" style="-aw-headerfooter-type: header-primary;">
        <p class="iw-signature" style="margin: 0pt;">
            <span class="iw-signature" style="font-family: Calibri; font-size: 11pt;">&nbsp;</span>
        </p>
    </div><p class="iw-signature" style="margin: 0pt 0pt 8pt; line-height: 108%; font-size: 11pt;">
        <span class="iw-signature" style="font-family: Arial; font-size: 11pt;">Kind regards,</span>
    </p><p class="iw-signature" style="margin: 0pt 0pt 8pt; line-height: 108%; font-size: 11pt;">
        <span class="iw-signature" style="font-family: Arial; font-size: 11pt;">This one is also with ARIAL 11.</span>
    </p><p class="iw-signature" style="margin: 0pt 0pt 8pt; line-height: 108%; font-size: 11pt;">
        <span class="iw-signature" style="font-family: Arial; font-size: 11pt;">Byeeeeeeeeeeee</span>
    </p>
    <div class="iw-signature" style="-aw-headerfooter-type: footer-primary;">
        <p class="iw-signature" style="margin: 0pt;">
            <span class="iw-signature" style="font-family: Calibri; font-size: 11pt;">&nbsp;</span>
        </p>
    </div>
</a>


您能告诉我什么是处理此问题的最佳方法吗?即使是解决方法,对我来说也意义重大。

嗨,Stefan,您能将代码发布到实际插入正文的位置吗?您的代码片段似乎只是在检索模板。我刚刚在最新的Outlook 2016:Office中尝试了此代码示例.context.mailbox.item.body.setAsync(“Hello”{importionType:“html”});它按预期工作。您使用的Outlook版本是什么?函数updateEmailBody(数据,回调){Office.context.mailbox.item.body.setAsync(数据,{importionType:factory.BodyType},函数(结果){if(回调)回调(结果)我用的是1701版,7766版。2076@StefanDjordjevic我试过这个