Office.context.document.customXmlParts未定义 [英] Office.context.document.customXmlParts is undefined

查看:109
本文介绍了Office.context.document.customXmlParts未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Office JS处理Excel加载项,在任务窗格中,我调用Office.context.document.customXmlParts.getByNamespaceAsync,但是它引发异常"TypeError:无法读取未定义的属性" getByNamespaceAsync"(即Office) .context.document.customXmlParts未定义

office-js版本是1.0.52

以下获取customXmlParts的方法有效:

     return await Excel.run(async ctx => {
        const workbook = ctx.workbook;
        workbook.load("customXmlParts");
        await ctx.sync();
        const items = workbook.customXmlParts.items;
        ...
    }
 

但是我需要调用getByNamespaceAsync才能在回调中使用Office.CustomXmlPart.value.addHandlerAsync,因此上述方法不合适.

请问有什么主意吗?

解决方案

这是因为Office.context.document.customXmlParts仅在word上受支持.请使用Excel.Workbook.customXmlParts代替Excel插件

https://docs.microsoft.com/zh-cn/office/dev/add-ins/reference/requirement-sets/office-add-in-requirement-sets#customxmlparts

I'm working on an Excel addin using Office JS, in a taskpane, I call Office.context.document.customXmlParts.getByNamespaceAsync, but it throws exception 'TypeError: Cannot read property 'getByNamespaceAsync' of undefined', namely Office.context.document.customXmlParts is undefined

The office-js version is 1.0.52

The below way to get the customXmlParts works:

    return await Excel.run(async ctx => {
        const workbook = ctx.workbook;
        workbook.load("customXmlParts");
        await ctx.sync();
        const items = workbook.customXmlParts.items;
        ...
    }

But I need to call getByNamespaceAsync to use the Office.CustomXmlPart.value.addHandlerAsync in the callback, so the above way doesn't suit.

Any idea please?

解决方案

That's because Office.context.document.customXmlParts only supported on word. Pls use Excel.Workbook.customXmlParts instead for Excel Addin

https://docs.microsoft.com/en-us/office/dev/add-ins/reference/requirement-sets/office-add-in-requirement-sets#customxmlparts

这篇关于Office.context.document.customXmlParts未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆