Created
January 1, 2016 23:24
-
-
Save crowcoder/586fe66f116f3949f92f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myTable; | |
// The initialize function is required for all apps. | |
Office.initialize = function (reason) { | |
$(document).ready(function () { | |
myTable = new Office.TableData(); | |
myTable.headers = ["First Name", "Last Name", "Grade"]; | |
myTable.rows = [["Brittney", "Booker", "A"], ["Sanjit", "Pandit", "C"], ["Naomi", "Peacock", "B"]]; | |
try { | |
Office.context.document.bindings.addFromNamedItemAsync('TheTable', | |
Office.BindingType.Text, { id: 'tbl' }, | |
function (result) { | |
if (result.status === Office.AsyncResultStatus.Succeeded) { | |
trace('Control bound. Binding.id: ' + result.value.id + ' Binding.type: ' + result.value.type); | |
} else { | |
trace('Error:', result.error.message); | |
} | |
}); | |
} catch (e) { trace("Exception: " + e.message); } | |
}); | |
} | |
function insertAtBinding() { | |
Office.context.document.goToByIdAsync("tbl", Office.GoToType.Binding, function (asyncResult) { | |
if (asyncResult.status == "failed") { | |
trace("Go To Binding failed with error: " + asyncResult.error.message); | |
} | |
else { | |
trace("Navigation successful"); | |
try { | |
Office.context.document.setSelectedDataAsync(myTable, | |
{ | |
coercionType: Office.CoercionType.Table | |
}, | |
function (asyncResult) { | |
if (asyncResult.status == "failed") { | |
trace("Action failed with error: " + asyncResult.error.message); | |
} else { trace("Success with addRowsWithoutSelection."); } | |
}); | |
} catch (e) { trace("Exception: " + e.message); } | |
} | |
}); | |
} | |
function trace(msg) { | |
$("#trace").append(msg + "<br />"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment