插入带有轨道更改的OOXML注释 [英] Insert OOXML comment with track changes

查看:147
本文介绍了插入带有轨道更改的OOXML注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Word加载项中,我要插入注释,方法是将所选文本替换为包含注释的OOXML.

In my Word add-in I am inserting comments by replacing the selected text with OOXML that contains the comment.

在启用跟踪更改"的情况下,Word将其注册为3个动作:delete + insert + comment.它甚至会插入一个段落分隔符,但我不确定是否与此相关.

With "Track Changes" turned on Word registers this as 3 actions: delete+insert+comment. It even inserts a paragraph break but I am unsure if that is related.

是否有一种方法只能将其注册为注释操作,例如使用Word功能插入注释时?

Is there a way to only have it register as a comment action like when inserting a comment using Word functionality?

使用 rangeObject.insertOoxml ,我尝试在开头插入在字符串的末尾没有任何运气,因为两个OOXML插入似乎没有关联(这很有意义):

Using rangeObject.insertOoxml I tried to insert at the beginning and at the end of the string without any luck since the two OOXML inserts does not seem to 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 to the beginning and the end of the range.');
    });
})
.catch(function (error) {
    console.log('Error: ' + JSON.stringify(error));
    if (error instanceof OfficeExtension.Error) {
        console.log('Debug info: ' + JSON.stringify(error.debugInfo));
    }
});

推荐答案

这是一个很好的问题,谢谢提出.当您使用insertOoxml方法时,实际上是在文档正文中编写,因此,在跟踪更改处于活动状态时观察到的行为是设计使然.到目前为止,还没有解决方法.当我们支持注释作为API的主要功能时(而不是插入ooxml作为解决方法),将解决此问题.请确保添加您的请求或对我们的uservoice中的现有投票进行投票! https://officespdev.uservoice .com/forums/224641-feature-requests-and-feedback/category/163566-add-in-word

This is a great question, thanks for asking it. When you use the insertOoxml method you are actually writing in the document's body, hence the behavior you observe when track changes is active, that's by design. There is no workaround for this, as of now. This issue will be solved when we support comments as a main feature of the API (and not inserting ooxml as workaround). Make sure to add your request or vote for an existing on in our uservoice! https://officespdev.uservoice.com/forums/224641-feature-requests-and-feedback/category/163566-add-in-word

顺便说一下,几个月前我们修复了一个错误,即insertOoxml方法正在插入一个额外的段落,请确保更新您的Word以获取最新的错误修复.如果仍然发生这种情况,请共享您的Office版本号.

Btw there was a bug we fixed a few months ago that the insertOoxml method was inserting a extra paragraph, make sure to update your Word to get the latest bug fixes. If this is still happening please share your Office Version number.

这篇关于插入带有轨道更改的OOXML注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆