我正在尝试使用office js提供的插入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);
有没有办法做到这一点?
发布于 2020-03-31 16:42:12
您可以使用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));
}
});
https://stackoverflow.com/questions/60951971
复制相似问题