Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/470.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Excel.Range.Insesrt Office JS api将单元格添加到表中_Javascript_Excel_Office Js_Office Addins - Fatal编程技术网

Javascript Excel.Range.Insesrt Office JS api将单元格添加到表中

Javascript Excel.Range.Insesrt Office JS api将单元格添加到表中,javascript,excel,office-js,office-addins,Javascript,Excel,Office Js,Office Addins,我试图使用office js提供的insert API将单元格添加到现有表中。微软官方文档提供了在表单中插入的示例代码,效果很好 Excel.run(function (context) { var sheet = context.workbook.worksheets.getItem("Sample"); var range = sheet.getRange("B4:E4"); range.insert(Excel.InsertShiftDirection.down)

我试图使用office js提供的insert API将单元格添加到现有表中。微软官方文档提供了在表单中插入的示例代码,效果很好

Excel.run(function (context) {
    var sheet = context.workbook.worksheets.getItem("Sample");
    var range = sheet.getRange("B4:E4");

    range.insert(Excel.InsertShiftDirection.down);

    return context.sync();
}).catch(errorHandlerFunction);
但我试着用床单上的桌子做同样的事情。但它不起作用

table = ctx.workbook.tables.getItem(tableName);
let range = table.getRange();
range.insert(Excel.InsertShiftDirection.down);

有没有办法做到这一点?

您可以使用
Excel.TableRow
,示例代码:

Excel.run(function (ctx) { 
    var tables = ctx.workbook.tables;
    var values = [["Sample", "Values", "For", "New", "Row"]];
    var row = tables.getItem("Table1").rows.add(null, values);
    row.load('index');
    return ctx.sync().then(function() {
        console.log(row.index);
    });
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

该文件可在

上找到,谢谢雷蒙德。但我正在寻找是否可以通过插入方法实现这一点。我只是在分析这部分。看来这是不可能的。