How to copy url to windows clipboard in office add-in?

陌路散爱 提交于 2021-01-07 01:06:07

问题


I am building an Office add-in to copy the URL of the opened Office document to the Windows clipboard.

But it doesn't work. Please let me know what my code is wrong.

Here's my FunctionFile.html for UI-less Office add-in.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--During development turn off caching-->
    <meta http-equiv="cache-control" content="max-age=0" />
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="expires" content="0" />
    <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
    <meta http-equiv="pragma" content="no-cache" />

    <title></title>
    <script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>

    <script>
        // The initialize function must be run each time a new page is loaded
        (function () {
            Office.initialize = function (reason) {
            };
        })();

        function copyLink(event) {
              Office.context.document.getFilePropertiesAsync(function (asyncResult) {
                  navigator.clipboard.writeText(asyncResult.value.url);
            });

            event.completed();
        }

    </script>
</head>
<body>
    Function file body is never displayed.
</body>
</html>

I tried this using execCommands, but it was not working as well.

来源:https://stackoverflow.com/questions/65149982/how-to-copy-url-to-windows-clipboard-in-office-add-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!