how to insert value to row cells adding new row in table using office js in word?

50 Views Asked by At

using This I am adding new row in table how can I give value to its cells

    await Word.run(async (context) => {
    const selection = context.document.getSelection();
    selection.load('parentTableCellOrNullObject');
    await context.sync();

    if (!selection.isNull && !selection.parentTableCellOrNullObject.isNull) {
        const parentCell = selection.parentTableCellOrNullObject;
        const parentRow = parentCell.parentRow;

        parentRow.insertRows(Word.InsertLocation.after, 1);

        await context.sync();
        console.log('Table row added after the selected row.');
    } else {
        console.log('Selection is not inside a table cell.');
    }
});
1

There are 1 best solutions below

1
Rick Kirkham On

You add the values as an additional parameter on the insertRow method. See insertRow. Alternatively, you can assign values to the row with the TableRow.values property.

You have made several StackOverflow questions in the last few days which indicate that you are making basic mistakes with the Office JavaScript APIs. Please make more of an effort to read the reference documentation before you post questions on StackOverflow.