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.