ms word - Insert OOXML comment with track changes -
in word add-in inserting comments replacing selected text ooxml contains comment.
with "track changes" turned on word registers 3 actions: delete+insert+comment. inserts paragraph break unsure if related.
is there way have register comment action when inserting comment using word functionality?
using rangeobject.insertooxml
tried insert @ beginning , @ end of string without luck since 2 ooxml inserts not seem relate (which makes sense):
word.run(function (context) { var range = context.document.getselection(); var prebody = '<?xml version="1.0" encoding="utf-8"?><pkg:package xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlpackage"><pkg:part pkg:name="/_rels/.rels" pkg:contenttype="application/vnd.openxmlformats-package.relationships+xml" pkg:padding="512"><pkg:xmldata><relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><relationship id="rid1" type="http://schemas.openxmlformats.org/officedocument/2006/relationships/officedocument" target="word/document.xml" /></relationships></pkg:xmldata></pkg:part><pkg:part pkg:name="/word/_rels/document.xml.rels" pkg:contenttype="application/vnd.openxmlformats-package.relationships+xml" pkg:padding="256"><pkg:xmldata><relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><relationship id="rid1" type="http://schemas.openxmlformats.org/officedocument/2006/relationships/comments" target="comments.xml" /></relationships></pkg:xmldata></pkg:part><pkg:part pkg:name="/word/document.xml" pkg:contenttype="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"><pkg:xmldata><w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p>'; var postbody = '</w:p></w:body></w:document></pkg:xmldata></pkg:part><pkg:part pkg:name="/word/comments.xml" pkg:contenttype="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml"><pkg:xmldata><w:comments xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officedocument/2006/relationships"><w:comment w:id="0" w:author="some user" w:date="2016-10-26t10:11:05" w:initials="su"><w:p><w:r><w:t>my comment</w:t></w:r></w:p></w:comment></w:comments></pkg:xmldata></pkg:part></pkg:package>'; var before = prebody + '<w:commentrangestart w:id="0" />' + postbody; var afterbody = '<w:commentrangeend w:id="0" /><w:r><w:commentreference w:id="0" /></w:r>'; var after = prebody + afterbody + postbody; range.insertooxml(before, word.insertlocation.start); range.insertooxml(after, word.insertlocation.end); return context.sync().then(function () { console.log('ooxml added beginning , end of range.'); }); }) .catch(function (error) { console.log('error: ' + json.stringify(error)); if (error instanceof officeextension.error) { console.log('debug info: ' + json.stringify(error.debuginfo)); } });
this great question, asking it. when use insertooxml method writing in document's body, hence behavior observe when track changes active, that's design. there no workaround this, of now. issue solved when support comments main feature of api (and not inserting ooxml workaround). make sure add request or vote existing on in our uservoice! https://officespdev.uservoice.com/forums/224641-feature-requests-and-feedback/category/163566-add-in-word
btw there bug fixed few months ago insertooxml method inserting paragraph, make sure update word latest bug fixes. if still happening please share office version number.
Comments
Post a Comment