2015-05-23 47 views
15

我的任務是把通過辦公室的JavaScript API評論一個Word文檔(.docx)到Word 2007或更高版本兼容英寸廣場評論1.1

我發現,有沒有直接的方式來通過Microsoft API來做到這一點。

因爲我能夠OOXML傳遞到Word文檔,我以爲我可以用它來放置註釋。

我做Word文檔結構一些研究,發現,該註釋被存儲在稱爲「comments.xml」,然後通過ID,在「document.xml中」引用的單獨的XML文件(I附相應樣本)。

是否有通過API,以便將註釋的Word文檔中編輯此comments.xml的方式或者是這個不是可能嗎?

樣本 「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> 

回答

2

這是大多數信息我已經能夠而找到與你研究這個:

https://msdn.microsoft.com/en-us/magazine/jj991976.aspx

注:一個好方法,瞭解如何從一個應用程序操縱OOXML是添加你想要使用的用戶界面(例如,通過點擊插入插入的SmartArt工作內容|插圖| SmartArt),使用getSelectedDataAsync獲取內容的OOXML,然後讀取結果。

我會做到這一點,然後把那些結果使用setSelectedDataAsync OOXML,這將回答你的問題。辦公室是否足夠聰明,可以自己創建這些引用,或者不是? (如果沒有,有什麼可以做這件事通過API)

OLD COMMENT(在那裏我找到了你的第一個前提是真實的。請忽略,或閱讀笑)

它看起來像您可以使用setSelectedDataAsync函數傳遞註釋值並將其應用於Word文檔中當前選定的內容。這裏有兩個最相關的片段:

Office.context.document.setSelectedDataAsync(data [, options], callback(asyncResult)); 

Office.CustomXMLNodeType.NodeComment "comment" The node is a comment. 

從微軟的一個例子使用coerciontype的實施,事實上,coerciontype是一個枚舉就像customexmlnodetype ...它使感覺到這會起作用。

function writeMatrix() { 
    Office.context.document.setSelectedDataAsync("test comment"], {CustomXMLNodeType: Office.Office.CustomXMLNodeType.NodeComment} 
    function (asyncResult) { 
     var error = asyncResult.error; 
     if (asyncResult.status === Office.AsyncResultStatus.Failed){ 
      write(error.name + ": " + error.message); 
     } 
    }); 

}

回首走過的文檔我現在發現coercionType作爲下一個對象可選參數,而不是所有的枚舉。這太愚蠢了!

這裏是我引用的信息:

檢查了這一點:https://msdn.microsoft.com/en-us/library/office/fp142145.aspx

這:https://msdn.microsoft.com/EN-US/library/office/fp142154.aspx