I have an Office Add-in using JavaScript API for Office 1.1. I am trying to highlight bindings in a Word document and bindings to cells in Excel documents so the user can easily recognize them.
I see the API allows formatting of TableBindings using setFormatsAsync but mine are Matrix and Text. I don't use Table type because it adds a header row and the total row messes up my logic.
Is there a way to format or highlight the bindings?
I will prefer this to be temporary - similar to the way the background color changes a bit when you hover on top of the binding but I can live with coloring the text and then removing the color.
You have several options here. To highlighting with formatting, use the RangeFormat object to modify the outline, background, or other properties. Here's the code for a background fill:
Excel.run(function (ctx) {
var myRange = ctx.workbook.bindings.getItem("myBinding").getRange();
myRange.format.fill.color = "FFFF00";
return ctx.sync();
});
Alternatively, you can draw the user's attention by causing their selection to move to the binding:
Excel.run(function (ctx) {
var myRange = ctx.workbook.bindings.getItem("myBinding").getRange();
myRange.select();
return ctx.sync();
});
Finally, if you want the code above to work in Excel 2013 too, you can accomplish the same thing with this snippet:
var myDoc = Office.context.document;
myDoc.goToByIdAsync("myBinding", Office.GoToType.Binding, function (asyncResult) {});
-Michael Saunders, program manager for Office add-ins