Pra*_*aba 5 javascript add-in office-app office-js
在文档或工作表中添加表行和列后,是否可以迭代它们.
我正在使用以下代码添加一个表,我希望这个代码成功我应该能够访问行和列应该能够在一些转换后替换单元格的值.Bellow是我用来创建表的代码.
var tableData = new Office.TableData();
var headers = [placeholder.columns.map(function (c) { return c.column; })];
tableData.headers = headers
tableData.rows = rows;
var document = Office.context.document;
document.setSelectedDataAsync(tableData, function (result) {
var placeholder = Office.context.document.settings.get(results.binding.id);
if (officeCallSucceded(result, true)) {
document.bindings.addFromSelectionAsync(Office.BindingType.Table, function (result) {
if (officeCallSucceded(result)) {
//SOME LOGIC FOR BINDING HERE TO ADD //EVENT handlers to the table just added
}
});
}
}
);
}
Run Code Online (Sandbox Code Playgroud)
是的,下面是在 Excel 中检索表的任何单独行的代码:
Excel.run(function (ctx) {
// substitute 'Table1' with the table you want and '0' with your row index
var myRow = ctx.workbook.tables.getItem('Table1').rows.getItemAt(0);
myRow.load('values');
return ctx.sync().then(function() {
console.log(myRow.values);
});
});
Run Code Online (Sandbox Code Playgroud)
替换一行内容:
Excel.run(function (ctx) {
var myNewRow = [["a", "b", "c"]];
// substitute 'Table1' with the table you want and '0' with your row
var row = ctx.workbook.tables.getItem('Table1').rows.getItemAt(0);
row.values = myNewRow;
return ctx.sync();
});
Run Code Online (Sandbox Code Playgroud)
在Word中有一个类似的TableRowCollection.getItem方法,但它仍处于预览状态:https://github.com/OfficeDev/office-js-docs/blob/WordJs_1.3_Openspec/word/resources/tablerowcollection.md#getitemindex-number
| 归档时间: |
|
| 查看次数: |
480 次 |
| 最近记录: |