Is there a way to insert a comment on the current selection using the MS Office Javascript API?
2 Answers
There is no direct 'add comment" method in the Office JavaScript API. However you can use setSelectedDataAsync with coercion type "OOXML". You can pass in an blob of OOXML (Office markup) that will be understood by Word and can insert comments that way. This blog post gives some information on inserting data with coercion type OOXML: http://blogs.msdn.com/b/officeapps/archive/2012/10/26/inserting-images-with-apps-for-office.aspx
Actually, it should work using OOXML. When writing WordOpenXML to a document the XML you provide is in the ODC "flat package" file format, which means you're passing in a complete Word document. All the individual XML "parts" are written out into single string. So you can provide not only document.xml content but other content, as well. Granted, this can be quite complex - but it is possible.
This article provides some basic information on the OOXML format (what it must contain, how it's constructed, etc.): https://msdn.microsoft.com/en-us/library/office/dn423225.aspx?f=255&MSPPError=-2147217396
If you feel more comfortable constructing the OOXML using the Open XML SDK it's possible to convert the "zip package" to the "flat file" using the tool published by Eric White: http://blogs.msdn.com/b/ericwhite/archive/2008/09/29/transforming-open-xml-documents-to-flat-opc-format.aspx