Skip to content

Instantly share code, notes, and snippets.

@crowcoder
Created January 1, 2016 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crowcoder/85203a0873a38ab942d9 to your computer and use it in GitHub Desktop.
Save crowcoder/85203a0873a38ab942d9 to your computer and use it in GitHub Desktop.
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 addHTML() {
try {
Office.select("bindings#tbl").setDataAsync("<table border='1' width='100%'><thead><tr><th style='background-color:#ff00ff'>Description</th><th>From</th><th>To</th></tr></thead></table>", { coercionType: "html" },
function (asyncResult) {
if (asyncResult.status == "failed") {
trace('Error with addHTML : ' + asyncResult.error.message);
} else { trace("Success calling addHTML()"); }
});
} 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