如何使用Word中的office js将值插入到行单元格中添加新行?

问题描述 投票:0回答:1

使用这个我在表中添加新行如何为其单元格赋予值

    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.');
    }
});
office365 office-js add-in word-addins
1个回答
0
投票

您将这些值添加为

insertRow
方法上的附加参数。请参阅插入行。或者,您可以使用 TableRow.values 属性为行分配值。

您在过去几天提出了几个 StackOverflow 问题,这表明您在使用 Office JavaScript API 时犯了基本错误。在 StackOverflow 上发布问题之前,请多花点功夫阅读参考文档。

© www.soinside.com 2019 - 2024. All rights reserved.