尝试在 table 行中插入内容控件时发生 GeneralException

GeneralException when try to insert content control in the table row

每次当我尝试在 table 行中插入 ContentControl 时,我都会遇到 GeneralException。 示例代码:

   Word.run(async (context) => {
       let table: Word.Table = context.document.getSelection().parentTable;
       table.load("rowCount, rows/items/cells/items/body");
       await context.sync();

       let rows: Word.TableRowCollection = table.rows;

       for (let i: number = 0; i < rows.items.length; i++) {
           let range: Word.Range = null;
           for (let j: number = 0; j < rows.items[i].cells.items.length; j++){
               if (range == null) {
                   range = rows.items[i].cells.items[j].body.getRange();
               } else {
                   range = range.expandTo(rows.items[i].cells.items[j].body.getRange());
               }
           }
           range.insertContentControl();
       }
       return context.sync();
   }).catch((error) => {
       this.errorEmitter.emit(error);
   });

这个错误我只在word online中遇到过。在桌面文字中,它完美无缺。 我做错了什么? tableExample.docx

对于这种情况,您的代码应该是正确的。 但是现在word online不支持table单元格和table行内容控件。这就是你得到这个例外的原因。