【问题标题】:Insert OOXML comment with track changes插入带有跟踪更改的 OOXML 注释
【发布时间】:2016-10-28 01:49:42
【问题描述】:

在我的 Word 加载项中,我通过将所选文本替换为包含注释的 OOXML 来插入 cmets。

打开“跟踪更改”后,Word 会将其注册为 3 个操作:删除+插入+注释。它甚至插入了一个分节符,但我不确定这是否相关。

有没有办法只将其注册为评论操作,例如使用 Word 功能插入评论时?

使用rangeObject.insertOoxml 我尝试在字符串的开头和结尾插入,但没有任何运气,因为两个 OOXML 插入似乎不相关(这是有道理的):

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));
    }
});

【问题讨论】:

    标签: ms-word office-js


    【解决方案1】:

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

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

    【讨论】:

    • 感谢胡安的回复。我真的很期待这个功能,因为它将极大地改进实时加载项。
    • 我注意到API的version 1.3中有Property &gt; comments。这是我们可以期望此功能可用的地方吗? uservoice 上已经有多个请求,例如 firstsecond
    • 我确实注意到额外的段落错误已修复。这一次它仅在启用跟踪更改时适用。 (由于字符限制,多个 cmets)
    • 很高兴看到它。我们绝对会考虑 uservoice 的反馈,以便将来添加到 API。顺便说一句,您所指的“cmets”属性并不完全是您的想法。我们将很快添加对自定义和内置文档属性的支持,您在规范中看到的“注释”指的是内置属性,而不是文档正文中的特定 cmets。 (它通常用于对文档的整体内容设置注释。
    • 这很有意义 :) 您的团队没有评论这两个用户语音请求,但 Ability to manipulate Excel comments 有。您会同时为所有应用程序提供内置 cmets 吗?你知道什么时候可以优先考虑吗?
    猜你喜欢
    • 2018-06-24
    • 1970-01-01
    • 2021-07-11
    • 1970-01-01
    • 1970-01-01
    • 2020-06-14
    • 2010-09-13
    • 1970-01-01
    相关资源
    最近更新 更多