0
votes

This is driving me mad - i am developing what i thought was a simple addin for MS word using React and office JS.

I am loading https://appsforoffice.microsoft.com/lib/beta/hosted/office.js in my app, I have a working manifest and can sideload the app which renders as expected, until i try to create my word interactivity. I have fallen on the first hurdle, i need my addin to get a docx document, and then load - which should be possible using createDocument(base64) then load.

my problem is that:

Word.run(async context => {
                var MyDoc = context.application.createDocument(getMyDocument());
                context.load(MyDoc);
            })
            .catch(function (error) { 
                console.log('Error: ' + JSON.stringify(error));
                if (error instanceof OfficeExtension.Error) {
                    console.log('Debug info: ' + JSON.stringify(error.debugInfo));
                }
        });

fails to compile with the error TS2339: Property 'application' does not exist on type 'RequestContext'.

however I can refer to context.document which will compile and add in paragraphs of text. I do not know where im going wrong at all.

Office version is Mac 2016 16.2 (181125) so should easily accept Word 1.3 API which has the functionality.

Googling has given no meaningful results which suggests its something i have missed rather than a common mistake.

Any help would be greatly appreciated.

1

1 Answers

0
votes

I have finally resolved this issue, it is down to the react library @types/office-js being out of date. The add-in was created using yeoman generator, and the @types/office-js had a version of 0.051^. I changed the package in packages.json and ran npm install to update to the latest (0.0170 at time of writing), which includes the contexts to work with the later versions of the word API, including createDocument and this worked.