Highlight bindings in a document

耗尽温柔 提交于 2019-12-11 04:46:25

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/38511026/highlight-bindings-in-a-document

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!