2016-04-27 119 views
1

我想在office.js中插入註釋到文檔中的Word加載項。在我看來,實現這一目標的唯一方法是使用OOXML。在Word中插入註釋使用office.js

我可以插入評論,但我的問題是,當我這樣插入段落中斷以及可以從此圖像中看到。

enter image description here

一個據我可以看到它歸結爲,如果我只是將一些文本的正文的內容看起來工作正常

<w:p> 
    <w:r> 
     <w:t>Some text</w:t> 
    </w:r> 
</w:p> 

以下,但如果我插入對評論的引用,它會導致段落在我正在插入的任何東西后面結束。在這種情況下,人體的內容是這樣的:

<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> 

用來替換高亮文本的JavaScript代碼如下所示:

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

被插入可以在這裏看到的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> 

對不起,特別長的職位。新用戶在插入鏈接和圖片:(

+0

一個建議,我可以提供的是創建一個非常簡單的文檔(與您在圖片中顯示的幾乎相同),保存它。創建註釋並再次保存,使用不同的名稱。現在使用Open XML SDK生產力工具並打開第一個文檔。工具的*比較*功能,你可以看到WordOpenXML的評論,就像在用戶界面中那樣,不會生成額外的段落 –

回答

0

這實際上是在API中確認的錯誤。針對此修復程序將推出爲即將到來的Office更新的一部分遺憾的限制。

+0

感謝您的快速回復,併爲我遲到的回覆感到遺憾您知道我在哪裏可以看到錯誤報告,何時下一次Office更新將推出? – jkh