I am working on a word web add-in that involves inserting some text (as OOXML) into a word document.
The insert functionality is working fine but I want the inserted text to have the same font size and colour etc as the area the user is currently editing.
I have got this working to some degree by getting the current paragraph at the cursor like so:
Word.run((context) => {
var pars = context.document.getSelection().paragraphs;
pars.load();
return context.sync().then(() => {
var par = pars.items[0];
var font = par.font.load();
var style = par.style;
// Do stuff with the style & font...
});
});
However this seems to be unreliable and sometimes doesn't work.
I want to get the style at the current typing location, or somehow read them directly from the values in the ribbon:
Is there a good way to do this? It seems like this would be a pretty common use case in a word add-in.