OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
682 stars 95 forks source link

Error: Office.js has not fully loaded. Your app must call "Office.onReady()" as part of it's loading sequence (or set the "Office.initialize" function). If your app has this functionality, try reloading this page. #246

Closed PeterTippett closed 5 years ago

PeterTippett commented 6 years ago

My code works with Online version and also with the Mac Version of Excel, but is failing with this error message for Windows Excel.

Error: Office.js has not fully loaded. Your app must call "Office.onReady()" as part of it's loading sequence (or set the "Office.initialize" function). If your app has this functionality, try reloading this page.

There is talk about onReady, but no real example of this being used.

Example Code

(function () {
    Office.initialize = function (reason) {
        $(document).ready(function () {

            if (!Office.context.requirements.isSetSupported('ExcelApi', 1.7)) {
                console.log('Sorry. The BSI People add-in uses Excel.js APIs that are not available in your version of Office.');
            } 

            $('#normal').click(normalTime);
            $('#night').click(nightShift);
            $('#over').click(overTime);
            $('#rosterover').click(rosteroverTime);
            $('#missedTime').click(missedTime);
            $('#missedOTime').click(missedOTime);

This based upon the Excel Tutorial for JQuery https://docs.microsoft.com/en-us/office/dev/add-ins/tutorials/excel-tutorial

There is about ~3,000 lines of code after this in the bundle.s file.

PeterTippett commented 6 years ago

Have found the difference. Javascript support differences.

I had done a copy array as let array1 = [...array2]; Changed to var array1 = array2.slice(0);

Had to get a Windows Machine and run this to test and found this problem. It had worked in all other environments.

JuaneloJuanelo commented 6 years ago

did you looked into this article? https://docs.microsoft.com/en-us/office/dev/add-ins/develop/understanding-the-javascript-api-for-office

there is a sample on how to initialize your add-in logic. please try an let us know if solved your issue.

michahell commented 6 years ago

What the hell. We're seeing this error popup all of a sudden, just before an important demo of our add-in... is using Office.onReady() all of a sudden a requirement? if so, when and where would this have been communicated?

if so, the documentation is definitely not up to date because it states that both mechanisms can still be used:

https://docs.microsoft.com/en-us/office/dev/add-ins/develop/understanding-the-javascript-api-for-office

michahell commented 6 years ago

Ah. all of a sudden it magically works again. intern deploy reverted, I guess...

hengchengfei commented 6 years ago

I have the same questions!

dmahugh commented 6 years ago

@michahell is it possible that you were on a slower network connection when you experienced the problems with Office.initialize()? There is no requirement to use Office.onReady() if you're using Office.initialize(), however there is a known issue with Office.initialize() on slow networks.

FYI, the documentation page has been updated to clarify the current behavior, as shown here: docsupdate

We're rolling out a change to eliminate the need for an empty Office.initialize() when using Office.onReady(), and will update the documentation to reflect this when that is done.

hengchengfei commented 6 years ago

It works when I developed in Visual Studio. But it doesn't work in Production Environment.

1

select '提取数据' add-in button.

2

https://www.chengfeisoft.com/dfzq-office/ExcelIndex.html

<?xml version="1.0" encoding="utf-8"?>
<OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0" xmlns:ov="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="TaskPaneApp">

  <!-- See https://github.com/OfficeDev/Office-Add-in-Commands-Samples for documentation-->

  <!-- BeginBasicSettings: Add-in metadata, used for all versions of Office unless override provided -->
  <!-- IMPORTANT! Id must be unique for your add-in, if you reuse this manifest ensure that you change this id to a new GUID. -->
  <Id>35a79b2a-a2c1-46a8-88d0-0b11ecd00b82</Id>

  <!--Version. Updates from the store only get triggered if there is a version change. -->
  <Version>1.0.0.0</Version>
  <ProviderName>chengfeisoft Inc.</ProviderName>
  <DefaultLocale>zh-CN</DefaultLocale>
  <!-- The display name of your add-in. Used on the store and various places of the Office UI such as the add-ins dialog. -->
  <DisplayName DefaultValue="东方证券估值模型" />
  <Description DefaultValue="©2015-2018 chengfeisoft.com.All Rights Reserved"/>
  <!--Icon for your add-in. Used on installation screens and the add-ins dialog -->
  <IconUrl DefaultValue="https://dfzq.chengfeisoft.com/icon_32x32.png" />
  <SupportUrl DefaultValue="https://www.chengfeisoft.com/dfzq-office/help/support.html"/>
  <AppDomains>
    <AppDomain>https://www.chengfeisoft.com</AppDomain>
  </AppDomains>
  <!--BeginTaskpaneMode integration. Office 2013 and any client that doesn't understand commands will use this section.
    This section will also be used if there are no VersionOverrides -->
  <Hosts>
    <Host Name="Workbook"/>
  </Hosts>

  <Requirements>
    <Sets DefaultMinVersion="1.1">
      <Set Name="ExcelApi" MinVersion="1.3"/>
      <Set Name="DialogAPI" MinVersion="1.1"/>
    </Sets>
  </Requirements>

  <DefaultSettings>
    <SourceLocation DefaultValue="https://www.chengfeisoft.com/dfzq-office/pages/login.html" />
  </DefaultSettings>
  <!--EndTaskpaneMode integration -->

  <Permissions>ReadWriteDocument</Permissions>

  <!--BeginAddinCommandsMode integration-->
  <VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0">

    <Hosts>
      <!--Each host can have a different set of commands. Cool huh!? -->
      <!-- Workbook=Excel Document=Word Presentation=PowerPoint -->
      <!-- Make sure the hosts you override match the hosts declared in the top section of the manifest -->
      <Host xsi:type="Workbook">
        <!-- Form factor. Currenly only DesktopFormFactor is supported. We will add TabletFormFactor and PhoneFormFactor in the future-->
        <DesktopFormFactor>
          <!--Function file is an html page that includes the javascript where functions for ExecuteAction will be called. 
            Think of the FunctionFile as the "code behind" ExecuteFunction-->
          <FunctionFile resid="DFZQ.FunctionFile.Url" />

          <!--PrimaryCommandSurface==Main Office Ribbon-->
          <ExtensionPoint xsi:type="PrimaryCommandSurface">
            <!--Use OfficeTab to extend an existing Tab. Use CustomTab to create a new tab -->
            <!-- Documentation includes all the IDs currently tested to work -->
            <CustomTab id="DFZQ.Tab1">
              <!-- Ensure you provide a unique id for the group. Recommendation for any IDs is to namespace using your company name. -->
              <Group id="DFZQ.Tab1.Group1">
                <!--Label for your group. resid must point to a ShortString resource -->
                <Label resid="DFZQ.Tab1.Group1.Label" />
                <!-- Sample Todo: Each size needs its own icon resource or it will look distorted when resized -->
                <!--Icons. Required sizes 16,31,80, optional 20, 24, 40, 48, 64. Strongly recommended to provide all sizes for great UX -->
                <!--Use PNG icons and remember that all URLs on the resources section must use HTTPS -->
                <Icon>
                  <bt:Image size="16" resid="DFZQ.icon16_16" />
                  <bt:Image size="32" resid="DFZQ.icon32_32" />
                  <bt:Image size="80" resid="DFZQ.icon80_80" />
                </Icon>

                <Control xsi:type="Button" id="DownloadReport">
                  <Label resid="DownloadReport.Label" />
                  <Supertip>
                    <!-- ToolTip title. resid must point to a ShortString resource. -->
                    <Title resid="DownloadReport.Label" />
                    <!-- ToolTip description. resid must point to a LongString resource. -->
                    <Description resid="DownloadReport.Tooltip" />
                  </Supertip>
                  <Icon>
                    <bt:Image size="16" resid="DFZQ.Menu_Download_16x16" />
                    <bt:Image size="32" resid="DFZQ.Menu_Download_32x32" />
                    <bt:Image size="80" resid="DFZQ.Menu_Download_80x80" />
                  </Icon>

                  <!-- This is what happens when the command is triggered (E.g. click on the Ribbon). 
                  Supported actions are ExecuteFunction or ShowTaskpane. -->
                  <Action xsi:type="ExecuteFunction">
                    <FunctionName>download</FunctionName>
                  </Action>
                </Control>

                <Control xsi:type="Button" id="GetData">
                  <Label resid="GetData.Label" />
                  <Supertip>
                    <!-- ToolTip title. resid must point to a ShortString resource. -->
                    <Title resid="GetData.Label" />
                    <!-- ToolTip description. resid must point to a LongString resource. -->
                    <Description resid="GetData.Tooltip" />
                  </Supertip>
                  <Icon>
                    <bt:Image size="16" resid="DFZQ.Menu_GetData_16x16" />
                    <bt:Image size="32" resid="DFZQ.Menu_GetData_32x32" />
                    <bt:Image size="80" resid="DFZQ.Menu_GetData_80x80" />
                  </Icon>

                  <!-- This is what happens when the command is triggered (E.g. click on the Ribbon). 
                  Supported actions are ExecuteFunction or ShowTaskpane. -->
                  <Action xsi:type="ExecuteFunction">
                    <FunctionName>fill</FunctionName>
                  </Action>
                </Control>

              </Group>

              <Group id="DFZQ.Tab1.Group2">
                <!--Label for your group. resid must point to a ShortString resource -->
                <Label resid="DFZQ.Tab1.Group2.Label" />
                <!-- Sample Todo: Each size needs its own icon resource or it will look distorted when resized -->
                <!--Icons. Required sizes 16,31,80, optional 20, 24, 40, 48, 64. Strongly recommended to provide all sizes for great UX -->
                <!--Use PNG icons and remember that all URLs on the resources section must use HTTPS -->
                <Icon>
                  <bt:Image size="16" resid="DFZQ.icon16_16" />
                  <bt:Image size="32" resid="DFZQ.icon32_32" />
                  <bt:Image size="80" resid="DFZQ.icon80_80" />
                </Icon>

                <Control xsi:type="Button" id="UpdateAnnual">
                  <Label resid="UpdateAnnual.Label" />
                  <Supertip>
                    <!-- ToolTip title. resid must point to a ShortString resource. -->
                    <Title resid="UpdateAnnual.Label" />
                    <!-- ToolTip description. resid must point to a LongString resource. -->
                    <Description resid="UpdateAnnual.Tooltip" />
                  </Supertip>
                  <Icon>
                     <bt:Image size="16" resid="DFZQ.Menu_Refresh_16x16" />
                    <bt:Image size="32" resid="DFZQ.Menu_Refresh_32x32" />
                    <bt:Image size="80" resid="DFZQ.Menu_Refresh_80x80" />
                  </Icon>

                  <!-- This is what happens when the command is triggered (E.g. click on the Ribbon). Supported actions are ExecuteFunction or ShowTaskpane. -->
                  <Action xsi:type="ExecuteFunction">
                    <FunctionName>update</FunctionName>
                  </Action>
                </Control>

                <Control xsi:type="Button" id="UpdateQuarterly">
                  <Label resid="UpdateQuarterly.Label" />
                  <Supertip>
                    <!-- ToolTip title. resid must point to a ShortString resource. -->
                    <Title resid="UpdateQuarterly.Label" />
                    <!-- ToolTip description. resid must point to a LongString resource. -->
                    <Description resid="UpdateQuarterly.Tooltip" />
                  </Supertip>
                  <Icon>
                     <bt:Image size="16" resid="DFZQ.Menu_Refresh_16x16" />
                    <bt:Image size="32" resid="DFZQ.Menu_Refresh_32x32" />
                    <bt:Image size="80" resid="DFZQ.Menu_Refresh_80x80" />
                  </Icon>

                  <!-- This is what happens when the command is triggered (E.g. click on the Ribbon). Supported actions are ExecuteFunction or ShowTaskpane. -->
                  <Action xsi:type="ExecuteFunction">
                    <FunctionName>update</FunctionName>
                  </Action>
                </Control>

                <Control xsi:type="Button" id="UpdateSingleseason">
                  <Label resid="UpdateSingleseason.Label" />
                  <Supertip>
                    <!-- ToolTip title. resid must point to a ShortString resource. -->
                    <Title resid="UpdateSingleseason.Label" />
                    <!-- ToolTip description. resid must point to a LongString resource. -->
                    <Description resid="UpdateSingleseason.Tooltip" />
                  </Supertip>
                  <Icon>
                     <bt:Image size="16" resid="DFZQ.Menu_Refresh_16x16" />
                    <bt:Image size="32" resid="DFZQ.Menu_Refresh_32x32" />
                    <bt:Image size="80" resid="DFZQ.Menu_Refresh_80x80" />
                  </Icon>

                  <!-- This is what happens when the command is triggered (E.g. click on the Ribbon). Supported actions are ExecuteFunction or ShowTaskpane. -->
                  <Action xsi:type="ExecuteFunction">
                    <FunctionName>update</FunctionName>
                  </Action>
                </Control> 

              </Group>

              <Group id="DFZQ.Tab1.Group3">
                <!--Label for your group. resid must point to a ShortString resource -->
                <Label resid="DFZQ.Tab1.Group3.Label" />
                <!-- Sample Todo: Each size needs its own icon resource or it will look distorted when resized -->
                <!--Icons. Required sizes 16,31,80, optional 20, 24, 40, 48, 64. Strongly recommended to provide all sizes for great UX -->
                <!--Use PNG icons and remember that all URLs on the resources section must use HTTPS -->
                <Icon>
                  <bt:Image size="16" resid="DFZQ.icon16_16" />
                  <bt:Image size="32" resid="DFZQ.icon32_32" />
                  <bt:Image size="80" resid="DFZQ.icon80_80" />
                </Icon>

                <Control xsi:type="Button" id="UpdateCategory">
                  <Label resid="UpdateCategory.Label" />
                  <Supertip>
                    <Title resid="UpdateCategory.Label" />
                    <Description resid="UpdateCategory.Tooltip" />
                  </Supertip>
                  <Icon>
                    <bt:Image size="16" resid="DFZQ.Menu_Refresh_16x16" />
                    <bt:Image size="32" resid="DFZQ.Menu_Refresh_32x32" />
                    <bt:Image size="80" resid="DFZQ.Menu_Refresh_80x80" />
                  </Icon>
                  <Action xsi:type="ExecuteFunction">
                    <FunctionName>update</FunctionName>
                  </Action>
                </Control>

               <Control xsi:type="Button" id="UpdateMainreve">
                  <Label resid="UpdateMainreve.Label" />
                  <Supertip>
                    <Title resid="UpdateMainreve.Label" />
                    <Description resid="UpdateMainreve.Tooltip" />
                  </Supertip>
                  <Icon>
                    <bt:Image size="16" resid="DFZQ.Menu_Refresh_16x16" />
                    <bt:Image size="32" resid="DFZQ.Menu_Refresh_32x32" />
                    <bt:Image size="80" resid="DFZQ.Menu_Refresh_80x80" />
                  </Icon>
                  <Action xsi:type="ExecuteFunction">
                    <FunctionName>update</FunctionName>
                  </Action>
                </Control>

                <Control xsi:type="Button" id="UpdateAll">
                  <Label resid="UpdateAll.Label" />
                  <Supertip>
                    <Title resid="UpdateAll.Label" />
                    <Description resid="UpdateAll.Tooltip" />
                  </Supertip>
                  <Icon>
                    <bt:Image size="16" resid="DFZQ.Menu_Refresh_16x16" />
                    <bt:Image size="32" resid="DFZQ.Menu_Refresh_32x32" />
                    <bt:Image size="80" resid="DFZQ.Menu_Refresh_80x80" />
                  </Icon>
                  <Action xsi:type="ExecuteFunction">
                    <FunctionName>update</FunctionName>
                  </Action>
                </Control>

              </Group>

              <!-- Label of your tab -->
              <!-- If validating with XSD it needs to be at the end, we might change this before release -->
              <Label resid="DFZQ.Tab1.Label" />
            </CustomTab>
          </ExtensionPoint>
        </DesktopFormFactor>
      </Host>
    </Hosts>
    <Resources>
      <bt:Images>
        <bt:Image id="DFZQ.icon16_16" DefaultValue="https://dfzq.chengfeisoft.com/icon_16x16.png" />
        <bt:Image id="DFZQ.icon32_32" DefaultValue="https://dfzq.chengfeisoft.com/icon_32x32.png" />
        <bt:Image id="DFZQ.icon80_80" DefaultValue="https://dfzq.chengfeisoft.com/icon_80x80.png" />

        <bt:Image id="DFZQ.Menu_Download_16x16" DefaultValue="https://dfzq.chengfeisoft.com/download_64x64.png" />
        <bt:Image id="DFZQ.Menu_Download_32x32" DefaultValue="https://dfzq.chengfeisoft.com/download_64x64.png" />
        <bt:Image id="DFZQ.Menu_Download_80x80" DefaultValue="https://dfzq.chengfeisoft.com/download_64x64.png" />

        <bt:Image id="DFZQ.Menu_GetData_16x16" DefaultValue="https://dfzq.chengfeisoft.com/Excel_GetData_16x16.png" />
        <bt:Image id="DFZQ.Menu_GetData_32x32" DefaultValue="https://dfzq.chengfeisoft.com/Excel_GetData_32x32.png" />
        <bt:Image id="DFZQ.Menu_GetData_80x80" DefaultValue="https://dfzq.chengfeisoft.com/Excel_GetData_80x80.png" />

        <bt:Image id="DFZQ.Menu_Refresh_16x16" DefaultValue="https://dfzq.chengfeisoft.com/Excel_Update_16x16.png" />
        <bt:Image id="DFZQ.Menu_Refresh_32x32" DefaultValue="https://dfzq.chengfeisoft.com/Excel_Update_32x32.png" />
        <bt:Image id="DFZQ.Menu_Refresh_80x80" DefaultValue="https://dfzq.chengfeisoft.com/Excel_Update_80x80.png" />

        <bt:Image id="DFZQ.Menu_ClearData_16x16" DefaultValue="https://dfzq.chengfeisoft.com/Excel_Clear_16x16.png" />
        <bt:Image id="DFZQ.Menu_ClearData_32x32" DefaultValue="https://dfzq.chengfeisoft.com/Excel_Clear_32x32.png" />
        <bt:Image id="DFZQ.Menu_ClearData_80x80" DefaultValue="https://dfzq.chengfeisoft.com/Excel_Clear_80x80.png" />

        <bt:Image id="DFZQ.Menu_Title_16x16" DefaultValue="https://dfzq.chengfeisoft.com/Excel_ViewComment_16x16.png" />
        <bt:Image id="DFZQ.Menu_Title_32x32" DefaultValue="https://dfzq.chengfeisoft.com/Excel_ViewComment_32x32.png" />
        <bt:Image id="DFZQ.Menu_Title_80x80" DefaultValue="https://dfzq.chengfeisoft.com/Excel_ViewComment_80x80.png" />

        <bt:Image id="DFZQ.Menu_ErrorSum_16x16" DefaultValue="https://dfzq.chengfeisoft.com/Excel_ErrorSum_16x16.png" />
        <bt:Image id="DFZQ.Menu_ErrorSum_32x32" DefaultValue="https://dfzq.chengfeisoft.com/Excel_ErrorSum_32x32.png" />
        <bt:Image id="DFZQ.Menu_ErrorSum_80x80" DefaultValue="https://dfzq.chengfeisoft.com/Excel_ErrorSum_80x80.png" /> 

      </bt:Images>
      <bt:Urls>
        <bt:Url id="DFZQ.FunctionFile.Url" DefaultValue="https://www.chengfeisoft.com/dfzq-office/ExcelIndex.html" />
      </bt:Urls>
      <!-- ShortStrings max characters==125. -->
      <bt:ShortStrings>
        <bt:String id="DFZQ.Tab1.Label" DefaultValue="东方证券估值模型" />
        <bt:String id="DFZQ.Tab1.Group1.Label" DefaultValue=" " />
        <bt:String id="DFZQ.Tab1.Group2.Label" DefaultValue=" " />
        <bt:String id="DFZQ.Tab1.Group3.Label" DefaultValue="   " />
        <bt:String id="DFZQ.Tab1.Group4.Label" DefaultValue="   " />

        <bt:String id="DownloadReport.Label" DefaultValue="下载估值模型" />
        <bt:String id="GetData.Label" DefaultValue="提取数据" />
        <bt:String id="UpdateAnnual.Label" DefaultValue="更新年报" />
        <bt:String id="UpdateQuarterly.Label" DefaultValue="更新季报" />
        <bt:String id="UpdateSingleseason.Label" DefaultValue="更新单季报" />
        <bt:String id="UpdateCategory.Label" DefaultValue="更新目录" />
        <bt:String id="UpdateMainreve.Label" DefaultValue="更新主营业务" />
        <bt:String id="UpdateAll.Label" DefaultValue="更新全部数据" />

        <bt:String id="ClearData.Label" DefaultValue="清空填写数据" />
        <bt:String id="ViewComment.Label" DefaultValue="查看批注" />
        <bt:String id="ErrorSum.Label" DefaultValue="报错统计" /> 

      </bt:ShortStrings>
      <!-- LongStrings max characters==250. -->
      <bt:LongStrings>
        <bt:String id="DownloadReport.Tooltip" DefaultValue="先下载估值模型,再填充" />
        <bt:String id="GetData.Tooltip" DefaultValue="点击提取数据" />
        <bt:String id="UpdateAnnual.Tooltip" DefaultValue="点击更新年报Sheet数据" />
        <bt:String id="UpdateQuarterly.Tooltip" DefaultValue="点击更新季报Sheet数据" />
        <bt:String id="UpdateSingleseason.Tooltip" DefaultValue="点击更新单季报Sheet数据" />
        <bt:String id="UpdateCategory.Tooltip" DefaultValue="点击更新目录Sheet数据" />
        <bt:String id="UpdateMainreve.Tooltip" DefaultValue="点击更新主营业务Sheet数据" />
        <bt:String id="UpdateAll.Tooltip" DefaultValue="点击更新全部Sheet数据" />

        <bt:String id="ClearData.Tooltip" DefaultValue="点击清空填写数据" />
        <bt:String id="ViewComment.Tooltip" DefaultValue="点击查看批注" />
        <bt:String id="ErrorSum.Tooltip" DefaultValue="点击报错统计" /> 
      </bt:LongStrings>
    </Resources>
  </VersionOverrides>
</OfficeApp>
michahell commented 5 years ago

@dmahugh OK, we're moving to the onReady() approach. We have also assigned an empty function to Office.initialize(). Everything seems to still work, the only thing I was wondering about: does it make sense to have a .catch() clause for the Promise returned by Office? what are the conditions for this to trigger? will it - in a sense - never trigger ?

Zlatkovsky commented 5 years ago

For the Office.onReady() Promise, it will never throw, so you don't need a catch. But for most other Promisy things (e.g., Excel.run(...) or context.sync()), remember that those do need proper error-handling, so don't let it lull you into a false sense of security for those other ones!

Kratikal-Yashu commented 3 years ago

Is this issue is fixed?

As I am still getting the same error when my outlook add-in loads. In some of the systems it's working fine but in most of the systems it shows the same error.

Is Office.js depends upon system configuration or browser or any compatibility issue?

sureshdube commented 3 years ago

I am facing the same error on macOS Catalina(14.15.7) for the outlook add-in. Is there any workaround to fix this error?

Kratikal-Yashu commented 3 years ago

I am facing the same error on macOS Catalina(14.15.7) for the outlook add-in. Is there any workaround to fix this error?

You can try converting the ES6 syntax to ES5 as the office add-in use Internet Explorer internally where ES6 is not supported in IE11. May be you are using the arrow function while calling the function office.onReady(() =>{})

You can refer to this too - https://github.com/OfficeDev/office-js/issues/1866

gourav-bk commented 3 years ago

I was facing the same issue and I have solved it by switching office 2019 to Office 365. This works fine now.

meisammofidi commented 1 year ago

I was facing the same issue and I have solved it by switching office 2019 to Office 365. This works fine now.

I am facing same error in same situation. When I am testing my office Word add-ins, it works on office 365 but throw error on office 2019. Error: "Office.js has not fully loaded. Your app must call Office.onReady()"