Ms word 使用office.js在Word中插入注释

Ms word 使用office.js在Word中插入注释,ms-word,office365,openxml,office-js,Ms Word,Office365,Openxml,Office Js,我试图在office.js中创建一个Word插件,在文档中插入注释。在我看来,实现这一点的唯一方法是使用OOXML 我可以插入注释,但我的问题是,当我这样做时,插入了一个段落分隔符,并且可以从该图像中看到 A据我所知,它可以归结为,如果我只是插入一些文本,正文的内容看起来如下,这很好 <w:p> <w:r> <w:t>Some text</w:t> </w:r> </w:p> 此处可以看到

我试图在office.js中创建一个Word插件,在文档中插入注释。在我看来,实现这一点的唯一方法是使用OOXML

我可以插入注释,但我的问题是,当我这样做时,插入了一个段落分隔符,并且可以从该图像中看到

A据我所知,它可以归结为,如果我只是插入一些文本,正文的内容看起来如下,这很好

<w:p>
    <w:r>
        <w:t>Some text</w:t>
    </w:r>
</w:p>
此处可以看到插入的OOXML:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?mso-application progid="Word.Document"?>
<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>
                        <w:commentRangeStart w:id="0"/>
                        <w:r>
                            <w:t>selectedText</w:t>
                        </w:r>
                        <w:r>
                            <w:commentReference w:id="0"/>
                        </w:r>
                        <w:commentRangeEnd w:id="0"/>
                    </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">
                <w:comment w:id="0" w:author="jkh" w:date="2016-04-27T08:15:00Z" w:initials="JH">
                    <w:p>
                        <w:r>
                            <w:t>comment</w:t>
                        </w:r>
                    </w:p>
                </w:comment>
            </w:comments>
        </pkg:xmlData>
    </pkg:part>
</pkg:package>

选定文本
评论

很抱歉,邮件太长了。很遗憾,新用户在插入链接和图像时受到限制:(

这实际上是API中的一个已确认错误。解决此问题的方法将作为即将到来的Office更新的一部分推出。

我可以提供的一个建议是创建一个非常简单的文档(与图片中显示的非常相似),保存它。创建注释并以其他名称再次保存。现在使用Open XML SDK生产力工具并打开第一个文档。使用该工具的比较功能,您可以在UI中看到注释的OpenXML字样,这不会生成额外的段落。感谢您的快速回复,并对我的延迟回复表示歉意。您认为呢知道我在哪里可以看到错误报告以及下一个Office更新何时发布吗?有关于此错误的更新吗?现在看来,它正在删除选择的后一个空间。
function insertComment() {
    Office.context.document.getSelectedDataAsync(
        Office.CoercionType.Text,
        function (result) {
            if (result.status == "succeeded") {
                // Get the OOXML returned from the getSelectedDataAsync call.
                var selectedText = result.value;
                var comment = getCommentAsOoxml(selectedText);
                Office.context.document.setSelectedDataAsync(comment, { coercionType: Office.CoercionType.Ooxml }, function (asyncResult) {
                    if (asyncResult.status == "failed") {
                        console.debug("Action failed with error: " + asyncResult.error.message);
                    }
                });
            }
        });
}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?mso-application progid="Word.Document"?>
<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>
                        <w:commentRangeStart w:id="0"/>
                        <w:r>
                            <w:t>selectedText</w:t>
                        </w:r>
                        <w:r>
                            <w:commentReference w:id="0"/>
                        </w:r>
                        <w:commentRangeEnd w:id="0"/>
                    </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">
                <w:comment w:id="0" w:author="jkh" w:date="2016-04-27T08:15:00Z" w:initials="JH">
                    <w:p>
                        <w:r>
                            <w:t>comment</w:t>
                        </w:r>
                    </w:p>
                </w:comment>
            </w:comments>
        </pkg:xmlData>
    </pkg:part>
</pkg:package>