枚举表和列表名称

我正在使用Office-js API(v1.1)来编写一些代码,大部分只是玩耍,试图做一些事情。 我可以使用代码示例并运行它们,但是我不太了解Javascript以知道我在做什么。

我举了一个枚举表的例子,并试图添加一些东西,但它不工作,我不知道为什么。 有人可以帮我从这里出去吗?

代码:

Excel.run(function (ctx) { var tables = ctx.workbook.tables; var tableNames = ctx.workbook.tables.load("name"); return ctx.sync().then(function() { console.log("Tables in workbook:"); if (tables.count = 0) { console.log("No tables found"); } else { for (var i = 0; i < tableNames.items.length; i++) { console.log(i + ": " + tableNames.items[i].name); } } console.log("------------------------"); }); }).catch(function (error) { console.log(error); }); 

在控制台日志中,我收到以下消息:

 Tables in workbook: TypeError: Assignment to read-only properties is not allowed in strict mode 

我基于此代码发现在这里: http : //officesnippetexplorer.azurewebsites.net/#/snippets/excel (select“表”,并摘录“在工作簿中获取表”)。 任何帮助将不胜感激!

谢谢,扎克·巴雷斯

我不认为你的意思是改变tables.count ,是吗?

这就是错误告诉你的 – 你有:

  if (tables.count = 0) { 

但你真的想要:

  if (tables.count == 0) { 

第一个尝试将tables.count设置为0 ,第二个testing如果tables.count等于0