【问题标题】:Officejs: get All customXmlParts from documentOfficejs:从文档中获取所有 customXmlParts
【发布时间】:2020-06-18 11:47:01
【问题描述】:

我正在使用 officeJS API 来创建 word 插件。我已将 CustomXMLParts 添加到文档中,但我无法从文档中检索所有可用的自定义 XML 部件。 OfficeJs 文档不提供任何 API 来获取所有自定义 XML 部分,我们可以通过命名空间或 id 获取这些部分。但是我们如何一次获得所有的 xml 部分呢?如果有人知道这种方法,请提供示例。

提前致谢, 普加。

【问题讨论】:

    标签: office-js word


    【解决方案1】:

    如何遍历命名空间并获取每个命名空间的 CustomXMLParts 并将它们全部推送到单个数组中?

    即创建一个字符串数组;命名空间。循环遍历数组。对于数组中的每个命名空间,按命名空间搜索。

    【讨论】:

    • 实际上我没有任何单一的命名空间来检索 customXMLParts。我只想要所有 customXMLParts。
    【解决方案2】:

    使用命名空间http://schemas.microsoft.com/office/2006/metadata/properties

    const NS = 'http://schemas.microsoft.com/office/2006/metadata/properties'
    Office.context.document.getByNamespaceAsync(NS, (result) => {
      // result.value contains the parts array
      const parts = result.value
      Office.context.document.getByIdAsync(parts[0].id, (result) => {
        const part = result.value
        part.getNodesAsync('*', (result) => {
          const nodes = result.value
          // do stuff wit hnodes
        })
      })
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-06
      • 1970-01-01
      • 2020-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多