2016-09-26 8 views
1

私は現在の修正されたドキュメントを.docxファイルとしてサーバーに送信する必要がある単語アドインを開発しています。現在のアップロード用APIを作成しますサーバー上のドキュメント(必要な場合)javascriptを使用してサーバにローカルのdocxファイルをアップロードするには

私は現在の文書をWordから取得してサーバーにアップロードする方法を教えてください。

ありがとうございました。

答えて

0

Office.context.document.getFileAsync(...)を使用します。

詳細はhttp://dev.office.com/reference/add-ins/shared/document.getfileasyncを参照してください。そのページからのサンプルのいずれかをコピーする

function getDocumentAsCompressed() { 
    Office.context.document.getFileAsync(Office.FileType.Compressed, { sliceSize: 65536 /*64 KB*/ }, 
     function (result) { 
      if (result.status == "succeeded") { 
       // If the getFileAsync call succeeded, then 
       // result.value will return a valid File Object. 
       var myFile = result.value; 
       var sliceCount = myFile.sliceCount; 
       var slicesReceived = 0, gotAllSlices = true, docdataSlices = []; 
       app.showNotification("File size:" + myFile.size + " #Slices: " + sliceCount); 

       // Get the file slices. 
       getSliceAsync(myFile, 0, sliceCount, gotAllSlices, docdataSlices, slicesReceived); 
      } 
      else { 
       app.showNotification("Error:", result.error.message); 
      } 
    }); 
} 

function getSliceAsync(file, nextSlice, sliceCount, gotAllSlices, docdataSlices, slicesReceived) { 
    file.getSliceAsync(nextSlice, function (sliceResult) { 
     if (sliceResult.status == "succeeded") { 
      if (!gotAllSlices) { // Failed to get all slices, no need to continue. 
       return; 
      } 

      // Got one slice, store it in a temporary array. 
      // (Or you can do something else, such as 
      // send it to a third-party server.) 
      docdataSlices[sliceResult.value.index] = sliceResult.value.data; 
      if (++slicesReceived == sliceCount) { 
       // All slices have been received. 
       file.closeAsync(); 
       onGotAllSlices(docdataSlices); 
      } 
      else { 
       getSliceAsync(file, ++nextSlice, sliceCount, gotAllSlices, docdataSlices, slicesReceived); 
      } 
     } 
      else { 
       gotAllSlices = false; 
       file.closeAsync(); 
       app.showNotification("getSliceAsync Error:", sliceResult.error.message); 
      } 
    }); 
} 

function onGotAllSlices(docdataSlices) { 
    var docdata = []; 
    for (var i = 0; i < docdataSlices.length; i++) { 
     docdata = docdata.concat(docdataSlices[i]); 
    } 

    var fileContent = new String(); 
    for (var j = 0; j < docdata.length; j++) { 
     fileContent += String.fromCharCode(docdata[j]); 
    } 

    // Now all the file content is stored in 'fileContent' variable, 
    // you can do something with it, such as print, fax... 
} 
+0

iは、サーバー上のファイルを送信する必要があるとして、私は下のリンクをたどってきた、ご返信いただきありがとうございます: 参照してくださいhttp://dev.office .com/docs/add-ins/power-for-add-in-for-add-in-for-powerpoint-or-word ドキュメントコンテンツをスライスで取得し、APIを使用して送信できますしかし、私はサーバー側でスライスを取得し、個々のスライスを単一の.docxファイルにコンパイルしてサーバーに格納する方法を知らない。 現在、スライスはbase64でデータを返します。サーバー側でドキュメントスライスを取得し、単一のdocxファイルを作成するように私に指示してください。 – user3931619

+0

JSをアセンブルしておく必要があります(これはonGotAllSlicesと同じです)。その後、大きな文字列としてサーバーに送信し、そこからファイルを操作するためにOpenXml SDKのようなものを使用します。 –

関連する問題