The Scenario
As I work on developing a Word add-in using the latest Javascript API's for Office, I have incorporated various functionalities along with templates. One of the client's requests is to have the templates accessible from the ribbon. Presently, there is a command add-in dropdown that connects each menu item to a function in the add-in's functions file. These functions utilize Word Javascript API methods to read and open a base64 string from a .docx file.
The Challenge
Opening simple files poses no issues, but more complex files containing images, content controls, etc. result in a 'GeneralException' error. While some suggest it may be due to images within the document, my experience contradicts this as documents with images still opened successfully. It leads me to believe that another element within the document might be causing trouble, yet I am uncertain!
Hence, I am seeking insights or explanations regarding this issue.
Code Snippet
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 form of assistance, suggestions, or guidance would be greatly appreciated.
UPDATE: Problem Identified
After conducting experiments, I have come to the following conclusion. The presence of rich text content controls in the header of a document hinders its opening using the method
context.application.createDocument
. Attempting to do so results in a 'GeneralException' without specific details. My suspicion leans towards a potential bug in the Office Javascript API.