枚举表和列表名称
Enumerate tables and list names
我正在编写一些代码,主要是使用 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 'Table' 和片段 'Get tables in workbook')。任何帮助将不胜感激!
谢谢,
扎克·巴雷斯
我不认为你打算改变 tables.count
,是吗?
这就是错误告诉您的内容 - 您有:
if (tables.count = 0) {
但你真的想要:
if (tables.count == 0) {
第一个尝试将 tables.count
设置为 0
,第二个测试 tables.count
是否等于 0
。
我正在编写一些代码,主要是使用 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 'Table' 和片段 'Get tables in workbook')。任何帮助将不胜感激!
谢谢, 扎克·巴雷斯
我不认为你打算改变 tables.count
,是吗?
这就是错误告诉您的内容 - 您有:
if (tables.count = 0) {
但你真的想要:
if (tables.count == 0) {
第一个尝试将 tables.count
设置为 0
,第二个测试 tables.count
是否等于 0
。