Ms word Word web加载项从服务器页眉/页脚加载整个文档

Ms word Word web加载项从服务器页眉/页脚加载整个文档,ms-word,ms-office,office-js,Ms Word,Ms Office,Office Js,我们正在尝试使用JavaScript从服务器加载word文档。我们使用base64编码发送文档。在我们当前的方法中,只有身体使用以下功能加载: context.document.body.insertFileFromBase64(fileContent, "replace"); 不幸的是,页眉和页脚没有加载。是否有其他方法加载整个文档,包括正文和页脚?根据我的研究,我在使用insertFileFromBase64时看到了这一点。文章说,如果使用insertFileFromBase64插入文件,

我们正在尝试使用JavaScript从服务器加载word文档。我们使用base64编码发送文档。在我们当前的方法中,只有身体使用以下功能加载:

context.document.body.insertFileFromBase64(fileContent, "replace");

不幸的是,页眉和页脚没有加载。是否有其他方法加载整个文档,包括正文和页脚?

根据我的研究,我在使用insertFileFromBase64时看到了这一点。文章说,如果使用insertFileFromBase64插入文件,它确实有一个带有页眉和页脚的空白页。你有同样的问题吗

然而,另一篇文章说这是一个设计问题

该条提供了以下方法:

function getFile(){
    Office.context.document.getFileAsync(Office.FileType.Compressed, { sliceSize: 4194304  /*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 = [];
              console.log("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();
            console.log("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]);
    }




    var mybase64 = window.btoa(fileContent);
    console.log("here is the base 64", mybase64);
    // Now all the file content is stored in 'fileContent' variable,
    // you can do something with it, such as print, fax...
}

insertFile操作不会覆盖文档中现有的页眉/页脚