我的任务是通过 Office Javascript API 在与 Word 2007 或更高版本兼容的 Word 文档 (.docx) 中添加评论。
我发现,没有直接的方法可以通过 Microsoft API 做到这一点。
由于我能够将 OOXML 传递给 Word 文档,因此我认为我可以使用它来发表评论。
我对 Word 文档结构进行了一些研究,发现评论存储在一个名为“comments.xml”的单独 XML 文件中,然后通过“document.xml”中的 ID 引用(我附上了相应的示例)。
有没有办法comments.xml
通过 API 进行编辑,以便在 Word 文档中添加评论,或者这不可能?
示例“document.xml”:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
mc:Ignorable="w14 wp14">
<w:body>
<w:p w:rsidR="00A9590C" w:rsidRDefault="0058668B">
<w:r>
<w:t>I am text.</w:t>
</w:r>
</w:p>
<w:p w:rsidR="0058668B" w:rsidRDefault="0058668B">
<w:commentRangeStart w:id="0"/>
<w:r>
<w:t>I am text with comment.</w:t>
</w:r>
<w:commentRangeEnd w:id="0"/>
<w:r>
<w:rPr>
<w:rStyle w:val="Kommentarzeichen"/>
</w:rPr>
<w:commentReference w:id="0"/>
</w:r>
</w:p>
<w:sectPr w:rsidR="0058668B">
<w:pgSz w:w="11906" w:h="16838"/>
<w:pgMar w:top="1417" w:right="1417" w:bottom="1134" w:left="1417" w:header="708" w:footer="708"
w:gutter="0"/>
<w:cols w:space="708"/>
<w:docGrid w:linePitch="360"/>
</w:sectPr>
</w:body>
示例“comments.xml”:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:comments
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
mc:Ignorable="w14 wp14">
<w:comment w:id="0" w:author="rz" w:date="2015-05-23T10:30:00Z" w:initials="r">
<w:p w:rsidR="0058668B" w:rsidRDefault="0058668B">
<w:pPr>
<w:pStyle w:val="Kommentartext"/>
</w:pPr>
<w:r>
<w:rPr>
<w:rStyle w:val="Kommentarzeichen"/>
</w:rPr>
<w:annotationRef/>
</w:r>
<w:r>
<w:t>Test</w:t>
</w:r>
<w:bookmarkStart w:id="1" w:name="_GoBack"/>
<w:bookmarkEnd w:id="1"/>
</w:p>
</w:comment>
</w:comments>