Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GeneralException when context.application.createDocument is called in Word Javascript API

The Context

Currently I am developing a Word add-in that uses the new Javascript API's for Office. The add-in consists of some basic functionalities and a number templates. One of the wishes from the client is to open the templates from the ribbon. Currently I have a command add-in dropdown, where each dropdown menu item refers to a function in the functions file of the add-in. These functions in turn call some Word Javascript API methods, that read and open a base64 string from a .docx file.

The Problem

Simple files are opened without any problems, however more complicated files that contain images, content controls, etc fail. The more complicated files raise a 'GeneralException'. The author of this issue states that it has to do with images that are contained within the document. However this does not align with my personal experience. Images can be added, and the document is still opened. So I assume some other part of the document might trigger problems, however I am not sure!

Therefore I was wondering whether someone is able to shed some more light on this problem.

Code

            Word.run(function(context) {
                let letterTemplate = context.application.createDocument(<base64string>);
                letterTemplate.open();

                return context.sync().then(function () {
                    console.log("success");
                })
                .catch(function (error) {
                    console.log(error);
                })
            });

Any help, tips or advice are welcome.

EDIT: Problem Identified

After some experimentation, I concluded the following. Whenever a (in this case rich text) content control is added to the header in a document, it cannot be opened with the method context.application.createDocument. Trying to do this will result in a 'GeneralException', which does give any specific information. My suspicion is that this is a bug in the Office Javascript API.

like image 406
Fluous Avatar asked Apr 22 '26 01:04

Fluous


1 Answers

If you are working on word online then please check whether your base64 is large than 4M. Currently base64 larger than 4M will fail with GeneralException. We are working on improve the limitation actively.

like image 94
MSFT-Jipyua Avatar answered Apr 23 '26 19:04

MSFT-Jipyua



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!