Change value of a table in content control

試著忘記壹切 提交于 2019-12-06 08:31:00

You can set table values in Word a similar way as you created them.

table.values = [["a", "b"], ["c", "d"]];

Here's an example of how that would look in your code:

Word.run(function (ctx) {
    var ctrl = ctx.document.contentControls.getByTag("MyTable1").getFirst();
    return ctx.sync().then(function () {
        if (!ctrl.isNull) { // found
            var newValue = [['a', 'b'], ['c', 'd']];
            ctrl.tables.getFirst().values = newValue;
            ctx.sync().then(function () {
                console.log('Table should be updated');
            }).catch(function (err) {
                console.log(err);
            });
        } else {
            console.log('Unable to find table.');
        }
    }).catch(function (err) {
        console.log(err);
    });
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!