Load document from local filesystem to Office online

余生颓废 提交于 2019-12-08 20:14:49

probably I am doing many assumptions with my answer, please correct me if I am wrong but I think what you want to do is a WORD Add-in (a task pane add-in) that exposes the following functionalities:

  1. Uploads the current document - to OneDrive for Business (basically what you are calling "Office Online" or whatever other cloud repository.
  2. Connects to OneDrive or any cloud repository and opens, enables the user to select a word File and open it, either on the current document or a new one.

and if those 2 assumptions are correct, i think you can actually build an add-in with such functionalities. BTW note that within the Word experience you can actually save and load Word files from OneDrive, so i am not sure i understand what you mean by "this is not part of the default functionality" .

Anyways here is what you can do with API:

  1. You can get the current file, either the docx, pdf or txt equivalents, for this you need to use the getFileAsync method. This method gives you the file encoded as base64 and you can then upload it wherever you need. you can slice the file as well if needed. Here is a good example on how to use the API.
  2. To open a file in the current document. For this, effectively, you need to use the document.body.insertFileFromBase64 method. This method works in Word for Windows, Online, Mac and iOS. Check out a sample here.
    1. Finally there is a PREVIEW api you can try to actually open the document in a different window. Check out the exercise #8 on this lab. Using the createDocument functionality. (note that you need to use the preview APIs as described here).

Now in order to connect to OneDrive and upload or get files as well as navigating the folder structure you need to use the graph API against one drive. Here is a good example on how to authenticate and make calls to the graph.

I know this is a bunch of information but should put you in the right direction.

Thanks and HAPPY CODING!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!