This must complete in 5 seconds or less
You can assign a handler to Office.initialize that implements your initialization logic.
You must set Office.Initialize, regardless of whether Office.onReady() is also called.
If you have no use for Office.Initialize, you can set it to an empty function as shown in the following example.

Office.initialize = function () {}; 

//The equivalent written in TypeScript would be:
Office.initialize = () => {};

Office.initialize = function () { 
    if (!Office.context.requirements.isSetSupported('ExcelApi', '1.7')) {
        console.log("Sorry, this add-in only works with newer versions of Excel.");

If you are using additional JavaScript frameworks that include their own initialization handler or tests, these should be usually be placed within the response to Office.onReady().
For example, JQuery's $(document).ready() function would be referenced as follows:

Office.initialize = function () { 
    // Office is ready
    $(document).ready(function () {
        // The document is ready

reason Parameter

For task pane and content add-ins, Office.initialize provides an additional reason parameter.
This can be used to identify how the add-in has been initialised.
There are two ways a task pane or content add-in can be initialized.
1 - The user has inserted it using Insert Add-in or from the Recently Used Add-ins list
2 - The user has opened a document that contains the add-in

The "reason" parameter provides access to the InitializationReason enumeration
The "reason" parameter is not required for Outlook Mail add-ins.

if (reason == Office.InitializationReason.Inserted) { 
    write("The add-in was just inserted/loaded.");

if (reason == Office.InitializationReason.DocumentOpened) {
    write("The add-in is already part of the document.");

Office.initialize = function (reason) { 
    $(document).ready(function () {
        switch (reason) {
            case 'inserted': console.log('The add-in was just inserted.');
            case 'documentOpened': console.log('The add-in is already part of the document.');

© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited TopPrevNext