Office.select

Allows support for the promises pattern for working with existing binding objects (getDataAsync, setDataAsync, addHandlerAsync, removeHandlerAsync)


link - docs.microsoft.com/en-us/javascript/api/office/office.binding?view=common-js-preview

function showBindingData() { 
    Office.select("bindings#MyBinding").getDataAsync(function (asyncResult) {
        write(asyncResult.value)
    });
}

function write(message){
    document.getElementById('message').innerText += message;
}

There is an important difference in behavior between using the "table" and "matrix" coercionType with the Binding.getDataAsync method, with respect to data formatted with header rows, as shown in the following two examples.
These code examples show event handler functions for the Binding.SelectionChanged event.
If you specify the "table" coercionType, the TableData.rows property ( result.value.rows in the following code example) returns an array that contains only the body rows of the table.
So, its 0th row will be the first non-header row in the table.

function selectionChanged(evtArgs) { 
    Office.select("bindings#TableTranslate").getDataAsync(
        { coercionType: 'table',
          startRow: evtArgs.startRow,
          startCol: 0,
          rowCount: 1,
          columnCount: 1 },
        function (result) {
            if (result.status == 'succeeded') {
                write("Image to find: " + result.value.rows[0][0]);
            }
            else
                write(result.error.message);
    });
}
function write(message){
    document.getElementById('message').innerText += message;
}

However, if you specify the "matrix" coercionType, result.value in the following code example returns an array that contains the table header in the 0th row.
If the table header contains multiple rows, then these are all included in the result.value matrix as separate rows before the table body rows are included.

function selectionChanged(evtArgs) { 
    Office.select("bindings#TableTranslate").getDataAsync(
        { coercionType: 'matrix',
          startRow: evtArgs.startRow,
          startCol: 0,
          rowCount: 1,
          columnCount: 1 },
        function (result) {
            if (result.status == 'succeeded') {
                write("Image to find: " + result.value[1][0]);
            }
            else
                write(result.error.message);
    });
}
function write(message){
    document.getElementById('message').innerText += message;
}


© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext