【问题标题】:Issue with getOoxml() and insertOoxml() for a ContentControl with in a Table表中的 ContentControl 的 getOoxml() 和 insertOoxml() 问题
【发布时间】:2022-08-02 19:31:17
【问题描述】:

我在一个表中有多个 contentConrols 并尝试实现隐藏/显示功能。
躲藏时获取Ooxml() 的 ContentControl 里面的表并删除它。
显示时 -插入Ooxml(xml,\'Replace\') 方法在同一个表中再次创建该 ContentControl。
但我面临以下两个问题。

  1. 如果我多次隐藏/显示(第二次尝试),则无法使用该 Ooxml 作为 ContentControl 插入
    并显示为已损坏。
  2. 使用 Insertooxml(xml,\'Replace\') 方法后,每次都会得到额外的段落。

    如果没有表格内的 ContentControl在文档中,它工作正常。

    有人可以帮我解决这些问题吗?

    标签: office-js openxml office-addins word-contentcontrol javascript-api-for-office


    【解决方案1】:

    感谢您报告此问题。它已被放入我们的积压工作<Bug#6255624> 以供内部跟踪。不幸的是,我们目前没有时间表可以分享。

    【讨论】:

      【解决方案2】:

      您可以尝试更新 Ooxml 并为要隐藏的内容控件添加“<w:vanish/>”标签,而不是从表中删除内容控件吗? Vanish 标记将隐藏内容控件而不是删除它。如果您想再次显示它,只需删除消失标签。

      const tableCells = tblRowXml[i]?.getElementsByTagName('w:tc');
      for (let j = 0; j < tableCells.length; j++) {
          let newCellPropertyWpPr = document.createElement('w:pPr');
          let newCellPropertyWrPr = document.createElement('w:rPr');
          let vanishProperty = '<w:vanish/>';
          newCellPropertyWrPr.innerHTML = vanishProperty;
          newCellPropertyWpPr.innerHTML = newCellPropertyWrPr.outerHTML;
      
          /* Add vanish nodes to table cell pPr */
          const pElement = tableCells[j]?.getElementsByTagName('w:p');
          if (pElement[0]) {
              pElement[0]?.insertBefore(newCellPropertyWpPr, pElement[0]?.childNodes[0]);
          }
      
      
          /* Add vanish nodes to table cell rPr */
          const rElement = tableCells[j]?.getElementsByTagName('w:r');
          if (rElement[0]) {
              rElement[0]?.insertBefore(newCellPropertyWrPr, rElement[0]?.childNodes[0]);
          }
      

      我们也为我们的单词插件做了类似的事情,如果它包含所有零值,我们将隐藏整个表格行。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-11-04
        • 1970-01-01
        相关资源
        最近更新 更多