0
我试图用通过Excel表格来遍历在Excel MAC表遍历办公室JS使用办公室的js不工作
下面是代码示例(同为一体,在文档这里https://github.com/OfficeDev/office-js-docs/blob/master/reference/excel/tablecollection.md):
Excel.run(function (ctx) {
var tables = ctx.workbook.tables;
tables.load('items');
return ctx.sync().then(function() {
console.log("tables Count: " + tables.count);
for (var i = 0; i < tables.items.length; i++)
{
console.log(tables.items[i].name);
}
});
}).catch(function(error) {
console.log("Error: " + error);
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
});
获取表的数量。
Excel.run(function (ctx) {
var tables = ctx.workbook.tables;
tables.load('count');
return ctx.sync().then(function() {
console.log(tables.count);
});
}).catch(function(error) {
console.log("Error: " + error);
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
});
代码正常的Windows版Excel 2016,但在Mac的Excel 2016都示例代码抛出类型的错误:“一般例外”,和错误的位置:“TableCollection.count”
我在Mac客户端遇到类似问题。对于新的工作簿 –
对于调用'var tables = ctx.workbook.tables; tables.load();'抛出一个错误,而不是返回成功与tables.count = 0和一个空的tables.items集合。错误是'{“errorLocation”:“TableCollection.count”}'。在我的情况下,当我使用API来添加表格时,即使存在表格,错误仍然会发生。解决方法的唯一方法是保存工作簿并重新打开它。然后tables.load()代码工作正常。只有在新的工作簿上才能看到问题。 –
Mac Version 15.30(170107) –