How can I format text without changing document state in MSWord web add-in API? - ms-word

I'm developing an add-in for MSWord using Microsoft web add-in API. I'd like to underline or highlight some given words, but only in the scope of that session. I don't want to change the document's state. In other words, I don't want to persist the new text formatting when the document is saved.
I know how to format text, but the document's state is changed. I have this code at the moment:
word_range.font.underline = Word.UnderlineType.wave;
I want to achieve a behavior similar to Grammarly plug-in, where the underline is only to point out something is wrong with those words, but again, without persisting the underlining.
I found a similar question (word - highlight search results without permanently changing document formatting), but it was asked a few years ago and the solution is not exactly what I'm looking for.

I'm afraid that there is no way to highlight that will automatically disappear if the user saves the document. The answer that you linked to, or this one is the best that can be done in Office.js right now. It is a good idea, however, so please suggest it at Office Developer Suggestion Box.

Related

Can I tag text for meaning using TinyMCE or some other rich text editor?

I'm not sure what this functionality or feature is technically called. I just tried asking the chat on their homepage and they suggested I try asking here to see if anyone else has done this.
We're looking to allow users to highlight text and connect a tag to that text so that it can be categorized and found in a search later on, or used in analytics. For example, if the highlighted text says, "His leadership skills were average," the user should be able to highlight that text and be offered to tag it with pre-built tags, in this case perhaps "leadership" and "neutral". That way a separate user can search for those tags later. What would this functionality be called?

Office JavaScript API: highlighting text in a document

I'm working on a side project using the Microsoft Office JavaScript APIs. I have been relying on the documentation to find my way around, but I've hit a wall trying to find something in the docs (perhaps it isn't there because it doesn't exist).
Recently I attempting to implement some functionality to highlight some text within a Word document. I don't want to modify the document, mind you; in other words I would rather not use something like ContentControl.insertHtml as that would change the actual content. What I want is to make the text temporarily highlighted (e.g., until the user clicks a "Cancel" button), much like what you see when you perform a search with Ctrl+F (and text matching your search is highlighted in yellow).
Is this possible using the Office JavaScript APIs?
Try getting a reference to the Range object and then setting Range.font.highlightcolor. Have a handler for the Cancel button click event that reverses the color change.
Here is a sample application that uses font.highlightcolor from the Office Javascript API. https://github.com/OfficeDev/Word-Add-in-JS-Redact/

Detect hover in Microsoft Word Add-In

I'm trying to develop an Add-In for Microsoft Word. The basic idea being to load some key words into the document and then when the user hovers over one of the key words a box pops up to show more information, like on Wikipedia or Facebook.
Looking over the api reference I see that the popup box isn't possible, and that's okay I could just make it appear in the Add-In's panel.
I read about bindings, but it seems they can't detect a hover or even a click event? I thought about hacking something together with links but I don't think that would be very UI friendly.
The only thing I can think of to make it kind of possible is to have the user manually highlight the key word (sometimes the key word is more than one word), then have them click a "search" button in the Add-In's panel that would read the selected range and compare it against a database of words. It just seems very anti user compared to the original idea.
Does anyone know of a better way to achieve this?

Getting HTML selection from document in a Word add-in

I'm creating a Office Word add-in that needs to fetch text and show it in the task pane. Since it would be preferred to show the text with the same formatting as in the host document, I'm using the getSelectedDataAsync() function and specifying Office.CoercionType.Html as coercion type. This works very well in Word online; but unfortunately not in Word 2013 and 2016 clients.
Looking at the documentation (http://dev.office.com/reference/add-ins/shared/document.getselecteddataasync), it says Office.CoercionType.Html is supported for Word but does not explicitly mention Word online. Judging from behaviour, it seems that the documentation is maybe faulty and should say the other way around.
But maybe I'm just missing something. Any ideas on why it's not working or how I can proceed to get it working? I would prefer to do minimal processing after getting the selection, which is why fetching it in HTML seemed to be the best solution. Fetching plain text does not even seem to take paragraphs into account which is a absolute minimum requirement of formatting.
The only really similar question I've found, Apps for Office 365 - Return selected text with styling and formatted, is related but does not answer my question.
This proved to be a problem not with Office.CoercionType.Html itself being unavailable, but rather it returning slightly different HTML in the Word clients and Word online. This made things break later in the code while applying some simple filters to the HTML which in turn made it look like the function did not return anything.
Like stated in the question the documentation is not completely obvious about the coercion type working in both Word clients and Word online, but I can hereby confirm that it does indeed work in both variants of Word.

Fill a Word 2010 form drop-down without using code?

I have been tasked with updating a Word 2010 fillable form for one of our departments. In various places in the form it uses a drop-down box with the same 20-or-so items in the list. I would like to make it so all occurrences of this box fill from a master list, thus making it easier to update in the future. I know in Excel you can do this with Data Validation and selecting a source list from somewhere else in the workbook. Is it possible to do something similar (reference a table, hidden text, etc) in Word? I have not been able to locate a feature in Word that looks promising, nor have my Google searches yielded anything useful. I realize this would probably work in VBA, but I'm hoping to avoid adding code to the workbook if possible. I would also prefer that the list be updateable by someone who does not know VBA. I'm not looking to do the impossible, so if you know for a fact that this cannot be done, say so and I'll move on.
Thanks.