Reputation: 1376
I have a Word table row with some cells bookmarked. I want to clone the row with similar but modified bookmarks. From what I have read I would want to use ooXml to achieve this - I don't see how to return a row or cell's range.
When trying to replace the table ooXml with the modified ooXml it embeds the table into what seems to be a new table.
I have a simple version below where I just retrieve the ooXml and insert it back and this same issue occurs:
Word.run(async context => {
let tblRange = context.document.body.tables.getFirst().getRange();
let tblXml = tblRange.getOoxml();
await context.sync();
tblRange.insertOoxml(tblXml.value, 'Replace');
await context.sync();
});
is this a bug or am I doing something wrong?
Upvotes: 0
Views: 170
Reputation: 1376
Explicitly deleting the range before replacing it seems to do the trick:
Word.run(async context => {
let tblRange = context.document.body.tables.getFirst().getRange();
let tblXml = tblRange.getOoxml();
await context.sync();
tblRange.delete(); // <-- Added this line
tblRange.insertOoxml(tblXml.value, 'Replace');
await context.sync();
});
Upvotes: 1