我在 Napa 进行黑客攻击的第一天,我很挣扎……
我正在努力理解 TableData 的绑定过程。我已经使用 Matrix 类型制定了一个简单的示例,并且可以从现有表中读取数据:
Office.context.document.bindings.addFromNamedItemAsync("Sheet1!Table1", Office.BindingType.Table, { id: "bindingTable" }, function (asyncResult) {
if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
asyncResult.value.getDataAsync(function (asyncResult) {
if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
console.log(asyncResult.value);
}
});
}
});
但我无法将数据写入表:
Office.context.document.bindings.addFromNamedItemAsync("Sheet1!Table1", Office.BindingType.Table, { id: "bindingTable" }, function (asyncResult) {
if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
var myTable = new Office.TableData;
myTable.headers = [["ID"],["Name"]];
myTable.rows = [[1,"Fred"],[2,"Jane"]];
asyncResult.value.setDataAsync(myTable, { coercionType: Office.CoercionType.Table }, function (asyncResult) {
console.log(asyncResult.status);
});
}
});
具体来说,抛出的错误是“数据写入错误”、“不支持提供的数据对象类型”。
我究竟做错了什么?
另外,我可以以编程方式在工作表上生成表格吗?
谢谢!