如何在Word加载项中打开新的Word docx文档 [英] How to open new Word docx document in word Add-in

查看:225
本文介绍了如何在Word加载项中打开新的Word docx文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Word javascript API开发了Word Add-in.我的Document .docx文件在服务器上,我需要在加载项上单击按钮,以新Word文档的形式打开该.docx文档.

I have developed a word add-in using word javascript api. My Document .docx file is on server and i need to open that .docx document as a new word document on a button click in add-in.

请指导我如何在Word加载项中打开新文档.

Please guide me how i can open new document in word add-in.

谢谢.

推荐答案

我们正在向API添加一种新方法,您可以实际使用它来实现此目的.请注意,它处于预览状态,这意味着将在几个月后投入生产.您需要最新的Office版本,并请参考我们的预览office.js进行尝试. office.js预览位于 https://appsforoffice.microsoft.com/lib/beta/hosted/office.js

There is a new method we are adding to the API that you can actually use to achieve this. Notice that is in preview, which means will be in production in a couple of months. You need latest Office version plus reference our preview office.js to try it. The office.js preview is here https://appsforoffice.microsoft.com/lib/beta/hosted/office.js

查看此代码示例以了解实现起来的容易程度.

Check out this code sample on how easy is to do it.

 function onaddOpenDoc() {
        Word.run(function (context) {
          
          // this getDocumentAsBase64 assumes a valid base64-encoded docx file
            var myNewDoc = context.application.createDocument(getDocumentAsBase64());
            context.load(myNewDoc);

            return context.sync()
                .then(function () {
                    myNewDoc.open();
                    context.sync();
                }).catch(function (myError) {
                    //otherwise we handle the exception here!
                    showNotification("Error", myError.message);
                })

        }).catch(function (myError) { showNotification("Error", myError.message); });


    }

这篇关于如何在Word加载项中打开新的Word docx文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆