使用办公室的js不工作
问题描述:
我试图用通过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”
答
我们试图重现这个问题,但没有得到“一般例外”。在“PropertyNotLoaded”的第一个示例中,我们遇到了一个错误,尽管从样本稍微不正确的意义上可以理解,但装入语句应该是tables.load('name, count')
而不是tables.load('items')
。但是这仍然不能解释错误。第二个样品应该可以正常工作。
您是否在现有文档上运行此操作?该文件有什么特别之处吗?如果你运行这个代码对付一个带有几个表格的全新文档,它会起作用吗?此外,什么版本号是您的Mac版Office?
我在Mac客户端遇到类似问题。对于新的工作簿 –
对于调用'var tables = ctx.workbook.tables; tables.load();'抛出一个错误,而不是返回成功与tables.count = 0和一个空的tables.items集合。错误是'{“errorLocation”:“TableCollection.count”}'。在我的情况下,当我使用API来添加表格时,即使存在表格,错误仍然会发生。解决方法的唯一方法是保存工作簿并重新打开它。然后tables.load()代码工作正常。只有在新的工作簿上才能看到问题。 –
Mac Version 15.30(170107) –