Matt3o
Matt3o

Reputation: 407

How to load a Word add-in with a specific file read from file system with Office.js

I'm a newbie in Office365 add-in development, and I'm trying create a poc for a office 365 word add-in and I need to load the add-in with a docx file read from filesystem (alternately from one-drive). Using

 Word.run(function (context) {
     var body = context.document.body;
     ...

the document is the current blank word document. Is it possible to start the add-in with a file read from file system? or one the add-in is loaded, can I open a docx file and work on it. I Search in the documentation, but I didn't find anything useful.

Thanks

Upvotes: 0

Views: 509

Answers (1)

Juan Balmori
Juan Balmori

Reputation: 5036

the method that you want to use in this case is the insertFileFromBase64 method. This method takes as first parameter a base64 encoded docx that then you can insert it.

Check out the reference here https://dev.office.com/reference/add-ins/word/body?product=word?product=word

note that you need to provide an experience of the user picking a file from the system (using regular HTML file controls) and then base-64 encode it.

Hope this sets you up in the right direction.

Upvotes: 2

Related Questions