Create new document with base64 using office javascript API in office 365

97 Views Asked by At

Using this I am creating new document with base64String in word this is working in word desktop version but this is not working on Office 365.

async function CreateNewDoc(event) {
    try {
        await Word.run(async (context) => {
            // Use the Base64-encoded string representation of the selected .docx file.
            const externalDocument = base64;
            var externalDoc = context.application.createDocument(externalDocument);
            await context.sync();
            externalDoc.open();
            event.completed();
            await context.sync();
        });
    } 
    catch (error) {
        event.completed();
        console.error(error);
    }
}

error message on Office 365 The action isn't supported by Word in a browser its mean this functionality is not supported office 365 yet?

error message image

1

There are 1 best solutions below

0
penglongzhaochina On BEST ANSWER

context.application.createDocument is not supported on Word online. You can get related information on this link[createDocument API definition][1]

[1]: https://learn.microsoft.com/en-us/javascript/api/word/word.documentcreated?view=word-js-preview. There have a lot of property have WordApiHiddenDocument 1.3 API set, which is a Desktop only set.

Thank you!