问题
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?
回答1:
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
来源:https://stackoverflow.com/questions/61435220/office-context-document-customxmlparts-is-undefined