-1

I have used following code for parsing Word document in an office app

var currentSlice = currentFile.getSliceAsync(0, function (resultSlice) {
   if (result.status == Office.AsyncResultStatus.Succeeded) {
  //We got the file slice. Now we will encode the data and post to a service
  var documentText = OSF.OUtil.encodeBase64(resultSlice.value);
  // Open the document, which is stored as a base64 string.
  var doc = new openXml.OpenXmlPackage(documentText);
   }
}

this works for Word 2013 but following line

OSF.OUtil.encodeBase64(resultSlice.value);

throws exception

Object doesn't support property or method 'charCodeAt'

on Word 2016.

Any idea about what are possible reasons?

Note i have used the latest Office.js from https://appsforoffice.microsoft.com/lib/1.1/hosted/office.js

Regards, Jhan Zaib

Jhanzaib
  • 1
  • 2
  • What's the type of `resultSlice.value`? You might need to call `toString()` on that. – Dirk Vollmar Dec 10 '15 at 14:28
  • yes tried to call toString() but the code break on line var doc = new openXml.OpenXmlPackage(documentText); now exception raised "Corrupted zip : can't find end of central directory" – Jhanzaib Dec 11 '15 at 11:34
  • Even though I may not have the answer I think you should take a look here. It may point you in the right direction. http://stackoverflow.com/questions/38332855/how-to-insert-an-image-into-word-from-a-url – EasyE Jul 28 '16 at 21:05

1 Answers1

2

The OSF.OUtil.encodeBase64(resultSlice.value); is intended to be used internally for Office.js consumption and it will not behave as you are expecting. Its not just encoding to base64. there are many libraries out there (available as freeware) that will help you encode the result of getSliceAsync (binary stream) into a base64 encoded string.

Juan Balmori
  • 4,898
  • 1
  • 8
  • 17