javascript - Excel.Range.Insesrt Office JS api 将单元格添加到表格
问题描述
我正在尝试使用 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);
有没有办法做到这一点?
解决方案
您可以使用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));
}
});
推荐阅读
- android - 如何将 Keras MobileNet 预处理单元引入 Android 应用程序?
- html - 将 div 缩放到父 div 的 100% 与同一级别的其他 div 的最简单方法?
- oracle - 在 PL/SQL 中调用存储过程时,在调用“DISP_EMP_DETAILS”时出现错误“参数数量或类型错误”
- node.js - Mongoose:每天创建多少用户
- android - 如何使 Theme.Holo 适应 App 主题?
- sql - 返回取决于数字的行数
- hdfs - 如何使用 hdfs dfs cp 和 xargs 来解决 linux 参数列表限制?
- c# - 使用 NetOffice 创建 PDF/A 文件
- javascript - 如何在 VueJS 3 中使用 9.0.1 Firebase 方法
- c++ - 照片的C++ DLL注入