问题
I would like to load/save a file directly from the local filesystem in Word online (without uploading it to onedrive). Since this is not part of the default functionality I am trying to determine if this would be possible with an addin.
The loading part:
The Document object gives access to body
load
and save
Methods however the documentation is unclear (to me) for load:Fills the proxy object created in JavaScript layer with property and object values specified in the parameter.
It seems there are options available like insertFileFromBase64
and insertOoxml
but unclear if those are only in (Windows) Desktop version or also in Online version. See this question
The saving part:
This seems to be the easier bit as there already is a Download
functionality to get a copy of the document.
Not looking for complete solution, just a "is it possible" and perhaps a few pointers to what methods to use.
回答1:
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:
- Uploads the current document - to OneDrive for Business (basically what you are calling "Office Online" or whatever other cloud repository.
- 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:
- 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.
- 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.
- 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!
来源:https://stackoverflow.com/questions/39890977/load-document-from-local-filesystem-to-office-online