When I manually (or via office.js code) insert rows into a table that is in a content control, it increases the number of content controls in the contentControls collection. Word 2016 Windows version 1611.
For example, if I have 1 table in 1 content control, initially the contentControls.items.length = 1. If I insert 3 rows, then the contentControls.items.length = 4.
Word.run(function (context) {
var contentCntrls = context.document.contentControls;
context.load(contentCntrls, "tag");
return context.sync().then(function () {
app.showNotification("contentCntrls.items.length: " + contentCntrls.items.length, "");
});
})
This produces errors ("Internal Error") in subsequent code that uses the contentControls collection and eventually freezes/crashes Word.
This behavior happens with both the beta and version 1 office.js code. The issue occurs on Windows, but works fine on Macs.
The count of content controls does not change if I check it via VBA: Debug.Print ActiveDocument.ContentControls.Count
If the user saves changes (after inserting rows), then the issue does not occur.
Is this a bug or am I doing something wrong? Is there some workaround (perhaps to reset the CC collection)?