office js - Header and footer is not binding in word javacript api -


i working microsoft word “add-in” 1 or our applications. using word plugin can add word templates our application. , can saved template application word if opening template saved header , footer getting application word, header , footer part not binding word document though saved header , footer while updating header , footer not binding. here code: ` function setdocumentdatabase64(data) { word.run(function (context) {

        // create proxy object document body.         var body = context.document.body;         //cleaning old context         //body.clear();          body.insertfilefrombase64(data, word.insertlocation.replace);          return context.sync().then(function () {             alert.success("document inserted");         });     })     .catch(function (error) {         console.log('error: ' + json.stringify(error));         if (error instanceof officeextension.error) {             console.log('debug info: ' + json.stringify(error.debuginfo));         }     }); }` 

i not sure mean "binding" on question (as "binding" specific concept in office.js). guessing trying insert document containing header/footers via range.insertfilefrombase64 , not seeing header , footers after insertion, if that's case design issue, , reason, don't want replace header/footer of current document. goal of method reuse chunks of documents, not replacing entire document.

if need change header, need manually.

you can explore createdocument api (who opens new document window) in preview , might need.

hope helps. thanks! juan.

this sample code of getting base64 of current document:

 function getfile(){          office.context.document.getfileasync(office.filetype.compressed, { slicesize: 4194304  /*64 kb*/ },            function (result) {                if (result.status == "succeeded") {                    // if getfileasync call succeeded,                    // result.value return 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);                      // 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 slices, no need continue.                      return;                  }                    // got 1 slice, store in temporary array.                  // (or can else, such                  // send third-party server.)                  docdataslices[sliceresult.value.index] = sliceresult.value.data;                  if (++slicesreceived == slicecount) {                      // 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 = [];          (var = 0; < docdataslices.length; i++) {              docdata = docdata.concat(docdataslices[i]);          }          var filecontent = new string();            (var j = 0; j < docdata.length; j++) {              filecontent += string.fromcharcode(docdata[j]);          }                          var mybase64 = window.btoa(filecontent);          console.log("here base 64", mybase64);          // file content stored in 'filecontent' variable,          // can it, such print, fax...      }


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -