【发布时间】:2017-09-06 00:22:43
【问题描述】:
我正在使用 Office JS API 开发 Word 加载项,尝试在文档中的表格绑定周围添加内容控件。
我遇到的问题是在选择了表格周围的绑定后,使用goToByIdAsync(),仅围绕表格的最后一行创建了内容控件,而不是选择。返回ctx.document.getSelection() 的值我可以看到选定的范围只是选定表中的最后一行。我需要使用 Binding 对象来了解 Table 的选定单元格范围。是不是我做错了什么?
var bindingId = '123';
var doc = Office.context.document;
// Create table in document.
doc.setSelectedDataAsync(tableValue, { coercionType: Office.CoercionType.Table }, function (asyncResult) {
// Add Binding to table
doc.bindings.addFromSelectionAsync(Office.BindingType.Table, { id: bindingId }, function (asyncResult) {
// Select the table object
doc.goToByIdAsync(bindingId, Office.GoToType.Binding, { selectionMode: 'selected' }, function (asyncResult) {
// Create Content Control
createCC();
});
});
});
function createCC(){
Word.run(function (ctx) {
var range = ctx.document.getSelection();
var html = range.getHtml();
return ctx.sync().then(function () {
console.log('Selected Range', html.value); // Only displays last row in the table.
var myContentControl = range.insertContentControl();
myContentControl.tag = bindingId;
myContentControl.title = 'My Content Control';
return ctx.sync().then(function () {
//Content control for table created
});
}).catch(function (err) {
errorHandler(err);
});
});
}
【问题讨论】:
标签: javascript office365 office-js word-addins