问题描述
我正在尝试为Web和Windows应用程序的Outlook创建一个加载项,有一次我想将JSON变量变量contact复制到剪贴板。
当前正在使用浏览器中的Outlook使用外接程序将内容复制到剪贴板,但是在Outlook Windows应用程序中使用外接程序时不会复制内容。 知道其他功能在两者中均有效,那么只有复制部分在两者中均无效!
我正在使用Yeoman生成器,这是我正在使用的复制命令。
function run() {
var messageBody = "";
var item = Office.context.mailBox.item;
item.body.getAsync(Office.CoercionType.Text,function (asyncResult) {
if (asyncResult.status !== Office.AsyncResultStatus.Succeeded) {
messageBody = asyncResult.error;
} else {
messageBody = asyncResult.value;
}
var copyhelper = document.createElement("input");
copyhelper.className = 'copyhelper'
document.body.appendChild(copyhelper);
copyhelper.value = JSON.stringify(messageBody);
copyhelper.select();
document.execCommand("copy");
document.body.removeChild(copyhelper);
});
}
我的问题是,为什么在Outlook应用程序中无法复制到剪贴板?以及如何使其工作?
谢谢!
更新
我已经更新了代码,以下是一个示例,在函数外部定义messageBody,然后在函数末尾将副本调用到copyToClipboard。 现在的好处是,它适用于Outlook应用程序和Web浏览器,但是仅当我在运行中单击两次时,才会复制到剪贴板。
所以我认为现在的问题是同步问题。 我尝试了多种解决方案,例如添加promise或await,但是没有任何效果。
var messageBody = "";
export async function run() {
Office.context.mailBox.item.body.getAsync(
Office.CoercionType.Text,function (asyncResult) {
if (asyncResult.status !== Office.AsyncResultStatus.Succeeded) {
messageBody = asyncResult.error;
} else {
messageBody = asyncResult.value;
}
});
copyToClipboard(messageBody)
}
function copyToClipboard(text) {
var copyhelper = document.createElement("input");
copyhelper.className = 'copyhelper'
document.body.appendChild(copyhelper);
copyhelper.value = text;
copyhelper.select();
document.execCommand("copy");
document.body.removeChild(copyhelper);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)